Sunteți pe pagina 1din 7

Floating number is an approximation to the real number 4//2 integer division 4/2 floating division 4%2=0; reminder operation;

% called mod 5%3 = 2; 2 is the reminder Python allows the instruction to expand multiple lines

X201: memory address Variable contains a memory address Variable refer to an value Value 8.5 has memory address

Python is case sensitive. dir( _builtins_ ): check build in functions Ctrl+F6 -> restart Python Shell, wiping out everything

Python can use both single quote and double quote. Quote is for internal user to use. So when you use print(hello), you only see: hello. Without quote mark. ha * 5 -> repetitive stuff, useful

When the function doesnt have a return statement, python returns none. And it is a none type. Triple quote can span multiple lines. Print ( how

Are You?) \n: new line character \t: new tab \\: print out a \ \: print out a single quote it can see \ is used to control sequences in this particular language just as LeTax does.

Writing documentation for the function Also all lines in the function should ben indented. Example: Def area(base, height): (number, number) Return something. This provides the documentation for the function.

Str(3) -> indicates str is a function int( 456 ) -> indicates int is a function help(math.sqrt) : math is the module name import(math) : import the math module when you use it, write as such: area = math.sqrt(xxx, xxx,xxx), you need to indicate the module name before the name of the function.

cbd in abcd -> in is a string operator

String index starts from 0. String index ends from -1 position, not from -0 position. Slicing uses [xxx], such as s[9:16]. (xxx) is reserved for the function argument. Also notice[a:b] include a but doesnt include b. In Python, we cant modify a string. But you can concanate a string and to make a new string.

Function within the module is called method All the function and methods acting on the string dont change the string, but create a new string.

For char in s: -> notice this typical syntax for for-loop in operation on string

Notice the difference in terminology: Parameter describing the argument used in the function definitions Argument describing the values passed to the function when running it.

Within the body of the function, notice the difference between print and return.

List type: a = [1 ,2, 3] In: a list operator, example: 60 in grades Data of different type can be in the same list: street_address = [10, main street] List used in the loop syntax: For grade in grades: Print (grade)

Grade here refers to each item in the list grades. color.append: append method in the list colors.extend: only take one argument which can be a list type. For example, colors.extend([allan, jat]) colors.pop() : remove the last item in the list colors.pop(2): remove the second last item in the list using an index. colors.remove(black): using the name to remove such item in the list.

List [0, 1, 2, 3] : just an object to containing the memory addresses such as address for integer 2 . List variable refers to the list address, like a = *0,1,2,3,4+. a actually contains the address of the list [0,1,2,3,4] Range: a function. For example: For num in range(10); print(num) other example, range(1, 16): start from 1 to 16, exclusive. Range (1, 16, 2): 2 is the step size.

Why we create the tuple object beyond list? Tuple is not mutable. Tup = (a, 3, -0.2) , you can see tuple uses (). Similar thing is tuple also uses indexing. List is mutable. The following notes only show the difference between list and dictionary: Dictionary uses , -, list uses *+ Syntax: assignment = ,a1:80, a2: 20-, a1 is the key, 80 is the value, and they are separated by : Dictionary is mutable. Key in dictionary can not be mutable. Key in the dictionary is unique.

Further study:

Compare these few books:

Think Python: How To Think Like a Computer Scientist How To Think Like a Computer Scientist: Learning with Python (original name)

Think Complexity: Exploring Complexity Science with Python Python for Software Design: How To Think Like a Computer Scientist (the same as Think Python: How To Think Like a Computer Scientist)

Good exercise

S-ar putea să vă placă și