编辑器:Welcome to Python.org
解释器:pycharm:Thank you for downloading PyCharm! (jetbrains.com)
print('Dad!!')
print('Dad!!')
print('Hello'+' world'+'!')
print('He said "good"')
# 使用转义字符\,向右边
print('He said \"Let\'s go\"')
He said "good"
He said "Let's go"
print("Hello!\nHi!")
Hello!
Hi!
print("""风萧萧兮易水寒,
壮士一去兮""")
风萧萧兮易水寒,
壮士一去兮
先赋值变量,后使用
greet ="您好,吃了么"print(greet+"张三")
print(greet+"李四")
您好,吃了么张三
您好,吃了么李四
greet ="您好,吃了么,"
greet_chinese = greet
greet_english = "Yo what's up,"
greet = greet_english
print(greet+"张三")
print(greet+"李四")print(greet_chinese+"张三")
print(greet_chinese+"李四")
Yo what's up,张三
Yo what's up,李四
您好,吃了么,张三
您好,吃了么,李四
只能由文字、数字、下划线组成
除下划线以外的符号不行
不能包含有空格
不能数字开头
变量名大小写敏感
关键字不能当作变量
加减乘除:±*/
乘方:**
import math
result = math.log2(8)
print(result)
import math
a=-1
b=-2
c=3
print((-b+math.sqrt(b ** 2 - 4 * a * c))/(2 * a))
print((-b-math.sqrt(b ** 2 - 4 * a * c))/(2 * a))
-3.0
1.0
# print("Hello!\nHi!")
快捷键ctl+/
'''
我是多行注释
我是多行注释
'''
str 字符串 ‘Hello’ “Hello”[3]获得第四个字符
int整数
float浮点数
bool布尔类型 True False
NoneType None表示完全没有值
type会返回对象的类型
# 对字符串求长度
s = 'Hello world!'
print(len(s))# 通过索引获取字符串单个字符
print(s[1])
print(s[11])
print(s[len(s)-1])# 布尔类型
b1 = True
b2 = False# 空值类型
n = None# type函数
print(type(s))
print(type(b1))
print(type(n))
print(type(1.5))
12
e
!
!
Process finished with exit code 0
针对文件一行一行解析和执行
直接一行出一个结果
cmd中输入python
quit()
或者ctrl+d
input一律返回字符串
用int函数将返回的字符串转成整数int,同理,float也是把其他类型转换成浮点,str