Python编程从入门到实践(学习备忘)

本次学习起始于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.注释

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值