IT-info > Python

Python

Python language info

Functions

print()
input()
int()
float()
bool()
type() # print(type(variable))
len()

print(f'{variable} is a variable') # formatted string
print(varaiable.method) # example: print(teststring.upper())

print methods

string_variable.upper()
string_variable.lower()
string_variable..title()
string_variable.find() # Returns the index of a character
string_variable.replace()

in method

'string_value' in string_variable

New line

\n = New line # example: print('Hello \nworld')

Arithmetic operators

print(10 + 3)
print(10 - 3)
print(10 * 3)
print(10 / 3) # 3.3333333333333335
print (10 // 3) # 3 (Returns the division result as an integer)
print(10 % 3) # 1 (Returns the remainder of the division)
print (10 ** 3) # 1000 (10 * 10 * 10)

x = 10

x += 3 # 13
x -= 3 # 7
x *= 3 # 30

print(x)

Operator precedence order

parenthesis
exponentiation 2 ** 3
multiplication or division
addition or subtraction

x = 10 + 3 * 2 # 16 (3 * 2 + 10, multiplication operator has a higher prescedence than addition operator)
x = 10 + 3 * 2 ** 2 # 22 ((2 * 2) * 3 + 10)
x = (10 + 3) * 2 ** 2 # 52 (13 * (2 * 2))
x = (2 + 3) * 10 - 3 # 47