python_1(基础知识)
2015-07-13 16:40
561 查看
2015年7月13日
今天是学习python的第一天 记录下:
python很强大 实用 方便 如果把C++比喻成机关枪的话,那么python就是氢弹了 (哈哈,开个玩笑,但是python的确很强大)
表达式:
>>> 1 + 2
3
直接得出结果 太方便
乘法
>>> 2 * 2
4
除法
>>> 1 / 2
0
因为都是整数 所以计算结果小数部分被截除了 我们可以这样
>>>1.0/2
0.5
取余
>>> 10/3
3
取模
>>>10%3
1
幂运算
>>> 2 ** 3
8
长整形数:
python为我们提供了直接可以用的方法 十分方便
>>>print 2137123123 * 213213213123
455662887894290343129
这个可能不太怎么体现出来 来个大的 嘿嘿
>>> print 534134354135413541 ** 1212 (534134354135413541的1212次方 怎么样 够大了吧) 由于数字过大 我截图了
额 后面还有一张 ---》一张不够
好了 谈谈字符串
>>> name = input("what you name?")
what you name? asdadasd
Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
name = input("what you name?")
File "<string>", line 1, in <module>
NameError: name 'asad' is not defined
这时就会报错
我们可以这样
>>> name = raw_input("what you name?")
what you name?asdsad
这样就没有错误了 我们打印一下
>>> print name
asdsad
如果我们需要进行长字符串的输入的话 可以这样
>>> print '''sadasd
asdas
d
asd
as
dqweqweqw
'''
sadasd
asdas
d
asd
as
dqweqweqw
在前面打三个''' 然后在结束的时候再回添''' 就OK了
还有转义字符的问题
>>> print "c:\nowhere"
c:
owhere
这样就会发生我们不愿意看到情况 这时 原始字符串开始派上用场了
>>> print r'c:\nowhere'
c:\nowhere
好了 暂时到这里
今天是学习python的第一天 记录下:
python很强大 实用 方便 如果把C++比喻成机关枪的话,那么python就是氢弹了 (哈哈,开个玩笑,但是python的确很强大)
表达式:
>>> 1 + 2
3
直接得出结果 太方便
乘法
>>> 2 * 2
4
除法
>>> 1 / 2
0
因为都是整数 所以计算结果小数部分被截除了 我们可以这样
>>>1.0/2
0.5
取余
>>> 10/3
3
取模
>>>10%3
1
幂运算
>>> 2 ** 3
8
长整形数:
python为我们提供了直接可以用的方法 十分方便
>>>print 2137123123 * 213213213123
455662887894290343129
这个可能不太怎么体现出来 来个大的 嘿嘿
>>> print 534134354135413541 ** 1212 (534134354135413541的1212次方 怎么样 够大了吧) 由于数字过大 我截图了
额 后面还有一张 ---》一张不够
好了 谈谈字符串
>>> name = input("what you name?")
what you name? asdadasd
Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
name = input("what you name?")
File "<string>", line 1, in <module>
NameError: name 'asad' is not defined
这时就会报错
我们可以这样
>>> name = raw_input("what you name?")
what you name?asdsad
这样就没有错误了 我们打印一下
>>> print name
asdsad
如果我们需要进行长字符串的输入的话 可以这样
>>> print '''sadasd
asdas
d
asd
as
dqweqweqw
'''
sadasd
asdas
d
asd
as
dqweqweqw
在前面打三个''' 然后在结束的时候再回添''' 就OK了
还有转义字符的问题
>>> print "c:\nowhere"
c:
owhere
这样就会发生我们不愿意看到情况 这时 原始字符串开始派上用场了
>>> print r'c:\nowhere'
c:\nowhere
好了 暂时到这里
相关文章推荐
- python第三方库系列之二十--批量机器配置管理库SaltStack
- Python程序的创建步骤
- python mysql
- python中的set集合操作
- python 运行时报错误SyntaxError: Non-ASCII character '\xe5' in file 1.py on line 2
- python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字
- python第三方库系列之十九--python测试使用的mock库
- python基础教程总结1——列表和元组
- python 目录文件操作 os模块
- python正则相关
- Python学习笔记——一些常用函数、常见错误总结
- python 模块==命名空间?
- python 打开一个文件并随机读取文件某一行
- Multiprocessing vs Threading Python
- python 之 模拟GET/POST提交
- Python Paste.deploy 笔记
- Python thread pool similar to the multiprocessing Pool?
- python 随机数
- python 计算器
- Python.Paste指南之Deploy