Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PRENOTES
- #=============================================================================
- #Installation of python2.7
- #print()
- #DATA TYPES
- #=============================================================================
- def f():
- print("This is a user-defined function")
- return True
- print("Some basic types in Python:")
- print(type(2)) # int
- print(type(2.2)) # float
- print(type("2.2")) # str (string)
- print(type(2 < 2.2)) # bool (boolean)
- print(type(math)) # module
- print(type(math.tan)) # builtin_function_or_method ("function" in Brython)
- print(type(f)) # function (user-defined function)
- print(type(type(42))) # type
- #x is an object
- x = 42
- print(x)
- print(type(x))
- x = "hello"
- print(x)
- print(type(x))
- x = 5.0
- print(x)
- print(type(x))
- print("Some builtin constants:")
- print(True)
- print(False)
- print(None)
- print("And some more constants in the math module:")
- import math
- print(math.pi)
- print(math.e)
- print("Strings:")
- print("hi from string one")
- print('hi from string two')
- print("Type casting functions:")
- print(bool(0)) # convert to boolean (True or False)
- print(float(42)) # convert to a floating point number
- print(int(2.8)) # convert to an integer (int)
- #OPERATORS
- #=============================================================================
- #Arithmetic +, -, *, /, //, **, %
- #Relational <, <=, >=, >, ==, !=
- print(3 * 2)
- print(3 * "abc")
- print(3 + 2)
- print("abc" + "def")
- print(3 + "def")
- print("Integer division:")
- print(" 5/3 =", ( 5/3))
- print("Float division:")
- print(" 5.0/3 =", ( 5.0/3))
- print(" 5/3.0 =", ( 5/3.0))
- print(" 6%3 =", ( 6%3))
- print(" 5%3 =", ( 5%3))
- print(" 2%3 =", ( 2%3))
- print(" 0%3 =", ( 0%3))
- print(" 3%0 =", ( 3%0))
- print("String operators:")
- print("hello " + "world!")
- print("hello " * 3)
- #PITFALLS
- #=============================================================================
- print("The problem....")
- d1 = 0.1 + 0.1 + 0.1
- d2 = 0.3
- print(d1 == d2) # False (never use == with floats!)
- #CLASS PROBLEMS
- #=============================================================================
- print(type("0.01"))
- print("hello " + 0 )
- print("1" + "2")
- print(3/5)
- print(3./5)
- #*supplementary exercise* negative-mod
- print("-4%3 =", (-4%3))
- print("4%-3 =", (4%-3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement