python note
时间:2009-03-17 来源:zsgd
1, about print
注意: 只要和字符串相关的都要有引号,单的双的都ok
2, 输出到文件
注意: 首先要open, 但不要忘记close
#!/bin/env python
import sys
outfile = open('/tmp/outfile.log','a')
user = raw_input("Please input your name:")
print >> outfile, user
outfile.close()
just to page 34
3,eg
#!/usr/bin/python
# Filename: while.py
number = 23
running = True
while running:
guess = int(raw_input('Enter an integer : '))
if guess == number:
print 'Congratulations, you guessed it.'
running = False # this causes the while loop to stop
elif guess < number:
print 'No, it is a little higher than that'
else:
print 'No, it is a little lower than that'
else:
print 'The while loop is over.'
# Do anything else you want to do here
print 'Done'
just page 52
注意: 只要和字符串相关的都要有引号,单的双的都ok
2, 输出到文件
注意: 首先要open, 但不要忘记close
#!/bin/env python
import sys
outfile = open('/tmp/outfile.log','a')
user = raw_input("Please input your name:")
print >> outfile, user
outfile.close()
just to page 34
3,eg
#!/usr/bin/python
# Filename: while.py
number = 23
running = True
while running:
guess = int(raw_input('Enter an integer : '))
if guess == number:
print 'Congratulations, you guessed it.'
running = False # this causes the while loop to stop
elif guess < number:
print 'No, it is a little higher than that'
else:
print 'No, it is a little lower than that'
else:
print 'The while loop is over.'
# Do anything else you want to do here
print 'Done'
just page 52
相关阅读 更多 +