$ python Python 2.6.4 (#1, Nov 11 2014, 13:34:43) [GCC 4.1.2 20120704 (Red Hat 5.6.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
>>> print "Hello, Python!";
| and | exec | not |
| assert | finally | or |
| break | for | pass |
| class | from | |
| continue | global | raise |
| def | if | return |
| del | import | try |
| elif | in | while |
| else | is | with |
| except | lambda | yield |
if True: print "True" else: print "False"
if True: print "Answer" print "True" else: print "Answer" print "False"
#!/usr/bin/python
import sys
try:
# open file stream
file = open(file_name, "w")
except IOError:
print "There was an error writing to", file_name
sys.exit()
print "Enter '", file_finish,
print "' When finished"
while file_text != file_finish:
file_text = raw_input("Enter text: ")
if file_text == file_finish:
# close the file
file.close
break
file.write(file_text)
file.write("
")
file.close()
file_name = raw_input("Enter filename: ")
if len(file_name) == 0:
print "Next time please enter something"
sys.exit()
try:
file = open(file_name, "r")
except IOError:
print "There was an error reading file"
sys.exit()
file_text = file.read()
file.close()
print file_text
total = item_one +
item_two +
item_three
days = ['Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday']
word = 'word' sentence = "This is a sentence." paragraph = """This is a paragraph. It is made up of multiple lines and sentences."""
#!/usr/bin/python # First comment print "Hello, Python!"; # second comment
name = "Madisetti" # This is again comment
# This is a comment. # This is a comment, too. # This is a comment, too. # I said that already.
#!/usr/bin/python
raw_input("Press the enter key to exit.")
import sys; x = 'foo'; sys.stdout.write(x + '')
if expression : suite elif expression : suite else : suite
$ python -h usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... Options and arguments (and corresponding environment variables): -c cmd : program passed in as string (terminates option list) -d : debug output from parser (also PYTHONDEBUG=x) -E : ignore environment variables (such as PYTHONPATH) -h : print this help message and exit [ etc. ]
>>> a = 2**3 >>> print a 8 >>>
>>> a = 3//1.7 >>> print a 1.0 >>>
>>> a = 6 >>> b=complex(a) >>> print b (6+0j) >>>
>>> a=3.14159 >>> b=100 >>> print coerce(a,b) (3.14159, 100.0) >>>
>>> a=9 >>> b=6 >>> print divmod(a,b) (1, 3) >>>
>>> a=2 >>> b=3 >>> print pow(a,b,5) 3
>>> print round(3.1415926,4) 3.1416 >>>
>>> arr = [1,1,5,6,9,7,3,2,11,56,45,78,100,55,0,5,9,10] >>> arr.append(89) >>> print arr [1, 1, 5, 6, 9, 7, 3, 2, 11, 56, 45, 78, 100, 55, 0, 5, 9, 10, 89] >>> print arr.count(5) 2 >>> arr1 = [123,456,789] >>> arr.extend(arr1) >>> print arr [1, 1, 5, 6, 9, 7, 3, 2, 11, 56, 45, 78, 100, 55, 0, 5, 9, 10, 89, 123, 456, 789] >>> arr.insert(1,999) >>> print arr [1, 999, 1, 5, 6, 9, 7, 3, 2, 11, 56, 45, 78, 100, 55, 0, 5, 9, 10, 89, 123, 456, 789] >>> arr.pop(0) 1 >>> print arr [999, 1, 5, 6, 9, 7, 3, 2, 11, 56, 45, 78, 100, 55, 0, 5, 9, 10, 89, 123, 456, 789] >>> arr.remove(999) >>> print arr [1, 5, 6, 9, 7, 3, 2, 11, 56, 45, 78, 100, 55, 0, 5, 9, 10, 89, 123, 456, 789] >>> arr.sort() >>> print arr [0, 1, 2, 3, 5, 5, 6, 7, 9, 9, 10, 11, 45, 55, 56, 78, 89, 100, 123, 456, 789] >>>
>>> dict = {'name':'goujinping','age':'21','sex':'man','school':'NEFU'}
>>> print dict
{'age': '21', 'school': 'NEFU', 'name': 'goujinping', 'sex': 'man'}
>>> dict['age']
'21'
>>> print dict['name']
goujinping
>>> print dict['age']
21
>>> for key in dict.keys():
print key
age
school
name
sex
>>> for value in dict.values():
print value
21
NEFU
goujinping
man
>>> del dict['sex']
>>> print dict
{'age': '21', 'school': 'NEFU', 'name': 'goujinping'}
>>> del dict['school']
>>> print dict
{'age': '21', 'name': 'goujinping'}
>>> del dict
>>> print dict
<type 'dict'>
>>>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有