Python-1-基础

获取用户输入
>>> x = input("x: ")
x: 34
>>> y = input("y: ")
y: 42
>>> print(int(x) * int(y))
1428
 
导入模块
>>> import math
>>> math.floor(32.9)
32
下面这样导入就不用指定模块名了
>>> from math import sqrt
>>> sqrt(9)
3.0
 
#井号注释
 
字符串转义
>>> "Let's go!"
"Let's go!"
>>> 'Let\'s go!'
"Let's go!"
 
字符串与值的转换
>>> print(repr("Hello,\nworld!"))
'Hello,\nworld!'
>>> print(str("Hello,\nworld!"))
Hello,
world!
 
多行长字符串用三引号
print('''This is a very long string. It continues here.
And it's not over yet. "Hello, world!"
Still here.''')
 
原始字符串
>>> path = 'C:\nowhere'
>>> path
'C:\nowhere'
>>> print(path)
C:
owhere
可以转义
>>> print('C:\\nowhere')
C:\nowhere
也可以用原始字符串让每个字符保持原样
>>> print(r'C:\nowhere')
C:\nowhere
>>> print(r'Let\'s go!')
Let\'s go
原始字符串不能以单个反斜杠结尾
>>> print(r'C:\Program Files\foo\bar' '\\')
C:\Program Files\foo\bar\
posted @ 2019-04-19 14:57  swefii  阅读(108)  评论(0编辑  收藏  举报