本次学习起始于2020年10月17日,起因是想要学习人工智能,把Python作为基础工具。
Python编程从入门到实践
第二章:变量和简单的数据类型
1.Python的变量始终记录最新值
2.变量命名规则
1)变量只能包含字母、数字、下划线,变量名只能以字母和下划线打头
2)变量名不能包含空格,要使用下划线来分隔单词
3)不把Python关键字和函数名用作变量名
4)谨慎使用小写字母i和o,以及数字0和1
3.字符串的使用
1)修改字符串大小写
在这里插入代码片name='you know the best "python"'
print(name.title())
print(name.upper())
print(name.lower())
首字母大写、字符串整体大写、字符串整体小写
2)在字符串中使用变量
my_name = "liu ren hong"
your_name = "da baby"
our_name = f"my_name, your_name.upper()"
print(our_name)
our_name = f"{my_name.title()}, {your_name.lower()}"
print(our_name)
our_name = f"{my_name.title()},_,{your_name.lower()}"
print(our_name)
our_name = f"{my_name.title()}, _ ,{your_name.lower()}"
print(our_name)
our_name = f"{my_name.title()}_{your_name.lower()}"
print(our_name)
3.制表符和换行符的使用和删除空白
\t \n
name='you know the best "python"'
print("you know the best 'python'")
print("\tyou\nknow\n\tthe\tbest\t\npython")
print("\tyou\nknow\n\tthe\tbest\n\tpython")
print("\tyou\nknow\n\tthe\tbest\n\t\n\n\npython")
name.rstrip()
name = name.rstrip()
print(name)
name = " python "
print(name)
name = name.rstrip()
print(name)
rstrip、lstrip、strip三个函数方便清空字符串的后、前、前后的空白,在清空空白后要重新赋值才能把清空后的保存下来
the_name = "eric"
print(f"hello {the_name.title()},would you like to learn some python today")
print(the_name.upper())
print(the_name.lower())
famous_person = "Albert Einstein"
Albert_Einstein_words = "A person who never made a mistake never tried anything new!"
print('Albert Einstein once said,"A person who never made a mistake never tried anything new!"')
print(f"{famous_person}once said {Albert_Einstein_words}")
print(f'{famous_person}oncesaid"{Albert_Einstein_words}"')
print(f'{famous_person}\n\tonce\tsaid\n\t\n"{Albert_Einstein_words}"')
famous_person = "\tAlbert\tEinstein"
print(famous_person)
print(famous_person.rstrip())
print(famous_person.lstrip())
print(famous_person.strip())
2+3
my_love = 16
MY_LOVE = 18
print(f"my\tfavourite\tnumber\tis\t{my_love}")
#向大家问好
print("hello everybody")
4.数
变量名全大写,视为常量
5.注释