Hello My Love Python.
I want to learn Python from long long ago when I am at Japan.
python use indent instead of () and {}, functionalable
python syntax
1. print
1 2 3
| print("hello-world") print(12 + 13) print("my first python code")
|
1 2
| name = input() print(name)
|
3. Boolean
basic Boolean
Boolean operator
eg.
1 2 3
| True and False True or False not True
|
4. if else statement
1 2 3 4
| if age >= 18: print("adult") else: print("teenager")
|
5. None
- Like java’s null or like scala’s None
6. Variable
1 2 3
| name = "Jack Zhao" true = True one = 1
|
1 2 3 4
| ''' multi rows comments '''
|
8. constant
9. unicode and utf-8
ord(‘A’): Get char ‘A’ unicode code
chr(65): change code to char
1 2 3 4
| print(ord('A')) >>>65 print(chr(65)) >>>A
|
10. str length
1 2 3 4
| len('ABC') >>>3 len('12') >>>2
|
1 2 3 4
| %d Int %f Float %s String %x Hex(16)
|
12. list and tuple
list: can been changed contents
1 2 3 4 5 6 7
| name = ['jack', 'joy', 'toy'] name[0] len(name) name.append('summer') name.append(1, 'summer') name.pop() name.pop(1)
|
tuple: can’t been changed
1
| name = ('jack', 'joy', 'toy')
|
if you define one Int content, you must use “,”, or will been think as defined a Int instead of a tuple.
Night is so long, end my active, go to sleep.