x = 3print(type(x)) # Prints "<type 'int'>"print(x) # Prints "3"print(x + 1 ) # Addition; prints "4"print(x - 1) # Subtraction; prints "2"print(x * 2 ) # Multiplication; prints "6"print(x ** 2) # Exponentiation; prints "9"
x += 1print(x) # Prints "4"
x *= 2print(x) # Prints "8"
y = 2.5print(type(y) )
print(y, y + 1, y * 2, y ** 2 )
t = True
f = False
print (type(t)) # Prints "<type 'bool'>"print( t and f)# Logical AND; prints "False"print (t or f ) # Logical OR; prints "True"print (not t) # Logical NOT; prints "False"print (t != f ) # Logical XOR; prints "True"
s = "hello"print (s.capitalize() ) # Capitalize a string; prints "Hello"print (s.upper() ) # Convert a string to uppercase; prints "HELLO"print (s.rjust(7) ) # Right-justify a string, padding with spaces; prints " hello"print (s.center(7) ) # Center a string, padding with spaces; prints " hello "print( s.replace('l', '(ell)') ) # Replace all instances of one substring with another;
# prints "he(ell)(ell)o"print (' world '.strip() ) # Strip leading and trailing whitespace; prints "world"