《python编程:从入门到实践》读书笔记1--字符串,数字
2018-02-20 15:54
232 查看
ubuntu桌面版+geany--->python3开发
python基本数据类型: 字符串(str), 数字(整数:int, 浮点数:float),
#####字符串 函数
name="i love python AAAdd a "
print(name.title())# 标题栏:首字母大写 I Love Python Aaadd A
print(name.lower())#全小写 i love python aaadd a
print(name.upper())#全大写 I LOVE PYTHON AAADD A
print(name.rstrip())#去尾空格:
print(name.strip())#去两头空格,中间不变
print("color:\n\tred\n\tblack\n\tblue")#换行符号,制表符
######数字 + 字符串
age=23
'''
mess="happy"+age+"thd birthday"
print(mess) #error : Can't convert 'int' object to str
'''
mess="happy "+str(age)+"thd birthday"
print(mess)
#####浮点数:加减乘除 python2.7
'''
>>> 0.1+0.2
0.30000000000000004
>>> 1/2
0
>>> 0.3+0.1
0.4
>>> 1.0/2
0.5
>>> 3/2
1
>>> 3.0/3
1.0
>>> 1/3.0
0.3333333333333333'''
######浮点数: 加减乘除 python3.5
'''
>>> 0.1+0.2
0.30000000000000004
>>> 0.3+0.1
0.4
>>> 1/2
0.5
>>> 1/3
0.3333333333333333
>>> 1.0/3
0.3333333333333333
'''
###python编程理想: python之禅
'''
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>
'''
python基本数据类型: 字符串(str), 数字(整数:int, 浮点数:float),
#####字符串 函数
name="i love python AAAdd a "
print(name.title())# 标题栏:首字母大写 I Love Python Aaadd A
print(name.lower())#全小写 i love python aaadd a
print(name.upper())#全大写 I LOVE PYTHON AAADD A
print(name.rstrip())#去尾空格:
print(name.strip())#去两头空格,中间不变
print("color:\n\tred\n\tblack\n\tblue")#换行符号,制表符
######数字 + 字符串
age=23
'''
mess="happy"+age+"thd birthday"
print(mess) #error : Can't convert 'int' object to str
'''
mess="happy "+str(age)+"thd birthday"
print(mess)
#####浮点数:加减乘除 python2.7
'''
>>> 0.1+0.2
0.30000000000000004
>>> 1/2
0
>>> 0.3+0.1
0.4
>>> 1.0/2
0.5
>>> 3/2
1
>>> 3.0/3
1.0
>>> 1/3.0
0.3333333333333333'''
######浮点数: 加减乘除 python3.5
'''
>>> 0.1+0.2
0.30000000000000004
>>> 0.3+0.1
0.4
>>> 1/2
0.5
>>> 1/3
0.3333333333333333
>>> 1.0/3
0.3333333333333333
'''
###python编程理想: python之禅
'''
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>
'''
相关文章推荐
- Python学习 第二天任务 (二:【基于Python编程从入门到实践】第二章 数字和注释 书本及动手试一试)
- Python学习 第二天任务 (一:【基于Python编程从入门到实践】第二章 变量和字符串 书本及动手试一试)
- Python编程:从入门到实践的动手试一试答案(第四章)
- Python编程:从入门到实践 5.4.3 练习 5-10 检查用户名
- 《python编程从入门到实践》15-10练习
- Python编程:从入门到实践(课后习题5)
- 【Python编程:从入门到实践】第九章:类
- 《Python编程:从入门到实践 》[Eric Matthes著] 中文pdf非扫描版
- python编程:从入门到实践 第八章课后题
- 【day 2】python编程:从入门到实践学习笔记-列表以及其操作
- python编程从入门到实践第四章习题
- 《Python编程-从入门到实践》第三章及第四章习题训练
- 《Python编程从入门到实践》_第四章_操作列表
- Python编程:从入门到实践(1-4)
- 《Python编程-从入门到实践》第9、10章习题选练
- python编程:从入门到实践 第十章习题
- Python编程:从入门到实践的动手试一试答案(第七章)
- python编程:从入门到实践 第5章
- 《Python编程-从入门到实践》第五章及第六 a067 章习题训练
- python编程:从入门到实践 第七章练习题