Python学习笔记第一天
每日一句:人生最重要的不是努力,不是奋斗,而是抉择。
1.查看python版本
window + r / window => cmd , enter => python -V
2.注释
单行注释:#
多行注释:""" """ 或 ''' '''
3.缩进:
表示属于同一个语句块
缩进空格需要保持相同
多行语句(\)[ ],( ),{ } 不需要
4.print() 打印
# window+r/window=>cmd,enter => python -V 查看python版本
# hello_world.py
# print 打印
print('Hello World ! ! !')
print('Hello Python ! ! !')
print('http://python.org/')
print('https://yjbys.com/mingyan/')

5.终端运行python文件:
1.window+r/window=>cmd,enter
2.输入cmd,enter
3.进入终端
4.cd 文件所在地址
5.python 文件名.py
1.基础知识:
1.变量
message="hello python world!!!" print(message) # 把等号右边的值赋值给左边 # 单个等号为赋值 # 两个等号为等于
变量的命名和使用
1、只包含字母、数字、下划线,不能以数字打头
2、不能包含空格,两个字母之间可以用下划线隔开:“驼峰式”
2、不用关键字和函数名作为变量名
4、简短而具有描述性
5、慎用大写O和小写l,形似数字0,1
6、尽量使用小写
import keyword keyword.kwlist # 保留字
保留字:
and exec not assert finally or break for pass class from print continue global raise
def if return del import try elif in while else is with except lambda yield
2.字符串
a="abc" b='字符串' print(a,b) # 用单引号与双引号引起来的叫字符串
字符串大小写操作
name='ada lovelace' print(name.title()) # title()每个单词首字母大写 print(name.upper()) # upper()每个单词首字母全部大写 print(name.lower()) # lower()每个单词首字母全部小写
Ada Lovelace ADA LOVELACE ada lovelace
合并字符串
first_name="abc"
print(first_name)
last_name="lovelace"
print(last_name)
full_name=first_name+" "+last_name
# 使用+来合并字符串
print(full_name.title())
print("hello"+","+full_name.title()+"!")
# 运用+组合成句子
message="hello"+","+full_name.title()+"!"
print(message)
# 把字符串合并,存储在变量中,再打印出来
abc lovelace Abc Lovelace hello,Abc Lovelace! hello,Abc Lovelace!
制表符,换行符
print("\tPython")
# \t 制表符
print("\nPython")
# \n 换行符
print("\tPython")
print("\n\tPython")
print("Languages:\nPython\nC\nJavascript")

删除空白
language=' python ' language.rstrip() # rstrip()去除字符串末尾空白 language=' python ' language.lstrip() # lstrip()去除字符串开头空白 language=' python ' language.strip() # lstrip()去除字符串两端空白
' python'
'python '
'python'
lstrip()、rstrip()、strip()只是暂时的改变,需要重新赋值,才能改变原来的值

浙公网安备 33010602011771号