Python笔记
来自Jack's Lab
(版本间的差异)
(→Strings) |
(→Operators) |
||
第71行: | 第71行: | ||
<br><br> | <br><br> | ||
+ | |||
+ | === Variable == | ||
+ | |||
+ | Python refers to anything used in a program as an object. | ||
+ | |||
+ | Do not need type declaration of variable in python | ||
+ | |||
+ | <br> | ||
== Operators == | == Operators == |
2017年4月16日 (日) 20:11的版本
目录 |
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 str_1 = 'Jack Tan' str_2 = "Ga Xiao Duo" str_3 = '''This is a multi-line string. first line. second line''' # using the startswith method of the string object if str_1.startswith('Ja'): print("Yes, str_1 start with 'Ja'") if 'a' in str_1: print('Yes, str_1 contains the string "a"') substr = 'ac' if str_1.find(substr) != -1: print('Yes, str_1 contains the string "{0}"'.format(substr)) print('Yes, {0} contains the string "{1}"'.format('str_1', substr)) print('Yes, {} contains the string "{}"'.format('str_1', substr)) # using the format method of the string object deli = '_*_' mylist = ['Brazil', 'Russia', 'India', 'China'] # using the join method of the string object 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
Once your have created a string, you cannot change it
3 = Variable
Python refers to anything used in a program as an object.
Do not need type declaration of variable in python
4 Operators
5 Control Flow
6 Functions
7 Data Structures
8 Exceptions
9 Modules
10 Object Oriented
11 Resource
- Online Python: http://www.compileonline.com/execute_python_online.php
- Python Quick Start: http://www.tutorialspoint.com/python/python_lists.htm