a=100
b=50
print(80)
print(a+b)
print(a)
print('WLD')
print("我嘞豆")
a=100
b=50
print(80,a,a+b,"我的天")#
python可以使用ASCII码显示字符串
print("b")#b
print(chr(98))#b
print("C")#C
print(chr(67))#C
print('c')#c
使用print函数将内容输出为中文Unicode码
print(ord('北'))
print(ord('京'))
print(chr(21271),chr(20140))
#21271 20140 北 京
使用print函数将内容输出到文件
cy=open('note.txt','w')#打开文件w-->write
print('人生只若如初见,何事秋风悲画扇。',file=cy)#将人生只若如初见,何事秋风悲画扇。写在文件中。
cy.close()#关闭文件
多条print函数输出一条显示
print('北京',end='-->')
print('h欢迎你')#北京-->h欢迎你
print('北京'+'欢迎你')#北京欢迎你
#只能是字符串和字符串连
print('北京'+'欢迎你'+2023)
#TypeError: can only concatenate str (not "int") to str
#将字符串改为大写或者小写
python
name="Love"
print(name.upper())
#LOVE
print(name.lower())
#love
input
连续输入输出
name=input('请输入你的姓名:')
print('我的名字是:'+name)
#请输入你的姓名:cy 我的名字是:cy
num=input('您的年龄是:')
print('您的年龄是:'+num)
num=int(num)
print('您的年龄是:'+num)
#TypeError: can only concatenate str (not "int") to str
num=input('您的年龄是:')
print('您的年龄是:'+num)
num=int(num)
print('您的年龄是:',num)
注释
单行注释
多行注释
中文编码格式
文件另存为时可以查看
代码缩进
#一般代码不需要缩进
print('hello')
#类的定义
class Student
pass
#函数的定义
def fun():
pass