您的位置:首页 > 编程语言 > Python开发

python学习笔记

2015-08-25 18:06 465 查看

python是完全面向对象语言

字符串

自然字符串: 如果你想要指示某些不需要如转义符那样的特别处理的字符串,那么你需要指定一个自然字符串。自然字符串通过给字符串加上前缀
r
R
来指定。例如
r"Newlines are indicated by \n"
。 

# FILENAME : 2.py
i = 5
print i
i=i+1;print i;

s='''this is a multi-line string.
this is the second line.'''
print s

q='''this is a multi-line string.\
this is the second line.'''
print q
输出:

jiao.geng@jiaogeng-Latitude-E5450:~/python$ python 2.py
5
6
this is a multi-line string.
this is the second line.
this is a multi-line string.this is the second line.


使用if语句

#!/usr/bin/python
# Filename: if.py

number = 23
guess = int(raw_input('Enter an integer : '))

if guess == number:
print 'Congratulations, you guessed it.' # New block starts here
print "(but you do not win any prizes!)" # New block ends here
elif guess < number:
print 'No, it is a little higher than that' # Another block
# You can do whatever you want in a block ...
else:
print 'No, it is a little lower than that'
# you must have guess > number to reach here

print 'Done'
# This last statement is always executed, after the if statement is executed
输出:

$ python if.py

Enter an integer : 50

No, it is a little lower than that

Done

$ python if.py

Enter an integer : 22

No, it is a little higher than that

Done

$ python if.py

Enter an integer : 23

Congratulations, you guessed it.

(but you do not win any prizes!)

Done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: