zl程序教程

您现在的位置是:首页 >  后端

当前栏目

跟我一起学Python从入门到精通《第一章》

Python入门 精通 一起 第一章
2023-06-13 09:13:13 时间
#作者: HY

#CSDN博客地址:https://blog.csdn.net/weixin_46152207

#开发时间:2021/8/19 17:31

# Print函数内容

#可以输出数字
print(520)
print(98.5)

#可以输出字符串
print("hello world")
#字符串需要加单引号或者双引号
print('hello world')

#含有运算符的表达式
print(3+1)

#将数据输出文件中,注意点,1.所指定的盘符存在 2.file=fp
fp=open('E:/text.txt','a+')  #如果文件不存在就创建,存在就在文件内容的后面追加
print('helloworld',file=fp)
fp.close()

#不进行换行输出(输出内容在一行当中)
print('hello','world','python')

#转义字符
#什么是转义字符?
#就是反斜杠+想要实现的转义功能首字母
print('hello\nworld')   #\ +转义功能的首字母  n-->newline的首字符表示换行
print('hello\tworld')   #t占位4个  具体占位几个取决与前面是否占4个占表位
print('hello\rworld')   #r回车   world讲hello进行了覆盖
print('hello\bworld')   #b退一个格
print('http:\\\\www.baidu.com')
print('老师说:\'大家好\'')

#原字符,不希望字符串中的转义字符起作用,就是用原字符,就是在字符串之前加上r,或R
print(r'hello\nworld')
#注意事项,最后一个字符不能是反斜杠
#print(r'hello\nworld\')
print(r'hello\nworld\\')  #两个\\没问题


#二进制与字符编码
print(chr(0b100111001011000))
print(ord('乘'))

#Python中的标识符和保留字
import keyword
print(keyword.kwlist)

#变量的定义和使用
name='玛丽亚'
print(name)
print('标识',id(name))
print('类型',type(name))
print('值',name)