python 练习一
来源:互联网 发布:数控车床编程实例 简单 编辑:程序博客网 时间:2024/05/17 13:42
1. 你理解的python是什么?为什么会使用python?
python是一个脚本语言,python 拥有强大的第三方库,开发的周期短,并且可移植较强
2. 解释python第一行怎么写?写的内容是做什么的?怎么写可移植性强?为什么?
#!/usr/bin/python #!/usr/bin/env python
第一行写的内容都是指定解释器的路径,不同的是,第二种制定方式能够适应不同的安装方式所安装的解释的路径
3. 解释编码格式ASCII,Unicode和utf-8的不同点?
ASCII 是美国制定的编码,只适用于英文字母,不支持其他语言的文字,Unicode能够适用于其它各种语言的文字,utf-8同样能够支持各种文字,而且能根据不同的符号而变化字节长度。
4. raw_input和input的区别
raw_input 是输入字符型 input 是输入整型
5. 三个双引号号(或者三个单引号的)可以用来做什么?
三个双引号可以编辑内容的格式 ,三个单引号可以多行注释
6. python格式化输出(包含变量)的方法有哪些?并举例列出?
[root@news ipython]# pythonPython 2.7.5 (default, Oct 11 2015, 17:47:16) [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> A = "word">>> print "hello" ,Ahello word>>> >>> A= 1>>> B= 2>>> print "the numner is",A,Bthe numner is 1 2>>> >>> A=1>>> B=2>>> print "the first num is %d ,the second num is %d" %(A,B)the first num is 1 ,the second num is 2>>> >>> A=1>>> B= "hello">>> print "the num is {} ,the string is {} " .format(A,B)the num is 1 ,the string is hello >>>
编程练习
- 用户登陆v1:
1). 假设系统中的用户名”root”,密码为”westos”;
2). 如果用户输入用户名和密码均正确显示”login ok”
如果用户名错误,显示”user is not exist”
如果密码错误,显示”password is no ok”
3). 只有三次登陆机会,超过三次,显示”count is bigger than 3”
- 用户登陆v1:
#!/usr/bin/env python#coding:utf-8"""file:.pydate:2017/8/25 0:06author: peakdescription:"""for i in range(1,4): user=raw_input("login name:") password=raw_input("password:") if user =="root" and password == "westos" : print "login ok" exit() elif user =="root": print "password is not ok" else: print "user is not exit"print "count is bigger than 3"
- 编写乘法表
#!/usr/bin/env python#coding:utf-8"""file:.pydate:2017/8/25 0:06author: peakdescription:"""for i in range(1,10): for n in range(1,i+1): print "{}*{}={}" .format(i,n,i*n) print " "
阅读全文
0 0
- Python脚本练习一
- Python小练习一
- python练习一
- python练习(一)
- python 练习一
- Python练习一
- Python练习一
- Python小练习(一)
- spark python 练习(一)
- Python爬虫练习笔记一
- python小练习(一)
- python项目练习一:即时标记
- python项目练习一:即时标记
- python 实验5 字符串练习(一)
- 13、python网络编程练习(一)
- 剑指offer练习Python(一)
- python项目练习一:即时标记
- Python List 练习实践(一)
- C++有趣的问题
- 初识python
- java动态/静态绑定以及双分派
- spring framework test3种方式
- Codeforces 785D Anton and School
- python 练习一
- ubuntu环境下vlcj报错:A fatal error has been detected #C [libc.so.6+0x121024] _IO_file_underflow+0x64
- 关于WebService 的用法demo 总结
- python-opencv3 kmeans图像分类
- python-opencv3 kmeans图像分类
- POJ.2236 Wireless Network (并查集)
- Ubuntu环境下vjudge系统搭建
- 流控制语句-break与label联用
- 尚不清晰或者未学习的东西