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
相关文章推荐
- python celery(任务调度器)
- python3爬虫 - 利用浏览器cookie登录
- python3爬虫 - 利用浏览器cookie登录
- python学习笔记之爬虫之爬取百度贴吧某一帖子
- 用python上手金融工程
- Python 虚拟环境:Virtualenv
- python报错
- 大数据全栈式开发语言 – Python
- 机器学习算法与Python实践之逻辑回归(Logistic Regression)
- python - encoding
- Python RuntimeError: thread.__init__() not called
- re,re.search,
- 【Python 练习】随机显示不重复的单词
- python的datetime模块实用小记
- python property装饰器
- Python图像处理库:Pillow 初级教程
- python学习--核心编程3习题解答以及知识点记录
- python学习笔记6—文件操作来生成船只侧面图像的描述文件
- python build in functions
- python学习笔记5—序列与列表的操作