Python笔记
来自Jack's Lab
(版本间的差异)
(→Functions) |
(→Basics) |
||
第14行: | 第14行: | ||
== Basics == | == Basics == | ||
+ | |||
+ | === Numbers === | ||
+ | |||
+ | <source lang=python> | ||
+ | Python 2.7.9 (default, Mar 1 2015, 12:57:24) | ||
+ | >>> a = 3.23 | ||
+ | >>> b = 4 | ||
+ | >>> c = 52.3E-4 | ||
+ | >>> print a, b, c | ||
+ | 3.23 4 0.00523 | ||
+ | </source> | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Strings === | ||
+ | |||
+ | <source lang=python> | ||
+ | #!/usr/bin/python | ||
+ | |||
+ | name ='Jack Tan' | ||
+ | |||
+ | if name.startswith('Ja'): | ||
+ | print("Yes, name start with 'Ja'") | ||
+ | |||
+ | if 'a' in name: | ||
+ | print('Yes, name contains the string "a"') | ||
+ | |||
+ | if name.find('ac') != -1: | ||
+ | print('Yes, name contains the string "ac"') | ||
+ | |||
+ | deli = '_*_' | ||
+ | mylist = ['Brazil', 'Russia', 'India', 'China'] | ||
+ | |||
+ | print(deli.join(mylist)) | ||
+ | </source> | ||
+ | |||
+ | Output: | ||
+ | |||
+ | <source lang=bash> | ||
+ | Yes, name start with 'Ja' | ||
+ | Yes, name contains the string "a" | ||
+ | Yes, name contains the string "ac" | ||
+ | Brazil_*_Russia_*_India_*_China | ||
+ | </source> | ||
<br><br> | <br><br> |
2017年4月16日 (日) 19:47的版本
目录 |
1 Quick Start
Install python2.7 from https://www.python.org/downloads/
Install pip:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py $ sudo python get-pip.py
2 Basics
2.1 Numbers
Python 2.7.9 (default, Mar 1 2015, 12:57:24) >>> a = 3.23 >>> b = 4 >>> c = 52.3E-4 >>> print a, b, c 3.23 4 0.00523
2.2 Strings
#!/usr/bin/python name ='Jack Tan' if name.startswith('Ja'): print("Yes, name start with 'Ja'") if 'a' in name: print('Yes, name contains the string "a"') if name.find('ac') != -1: print('Yes, name contains the string "ac"') deli = '_*_' mylist = ['Brazil', 'Russia', 'India', 'China'] print(deli.join(mylist))
Output:
Yes, name start with 'Ja' Yes, name contains the string "a" Yes, name contains the string "ac" Brazil_*_Russia_*_India_*_China
3 Operators
4 Control Flow
5 Functions
6 Data Structures
7 Exceptions
8 Modules
9 Object Oriented
10 Resource
- Online Python: http://www.compileonline.com/execute_python_online.php
- Python Quick Start: http://www.tutorialspoint.com/python/python_lists.htm