今天自学python第一天,开通博客希望能坚持下去,每天学习点。
是今天学习的内容有变量和一些循环
变量的命名和使用
1.变量名只能包含数字小写和下划线
2,变量名不能包含空格
3.不能将关键字和函数名作为变量名
4.简短有描述性
5.慎用字母l和O
6.应使用小写作为变量名
使用方法修改字符串的大小写
1 abc_1 = "'224adffsdgs2DFGGH22'" 2 print(abc_1) 3 print(abc_1.title()) 4 #首字母大写输出 5 print(abc_1.upper()) 6 #全大写输出 7 print(abc_1.lower()) 8 #全小写输出
字符的拼接
abc_2 = 1 + 2 #结果 3 print(abc_2) first_name = "zhang" last_name = "hongjia" full_name = first_name.title() + last_name.title() hello = "Hello,"+ full_name + "!" print(hello) #结果 Hello,ZhangHongjia!
删除空白
rstrip() 右边删除 (后边)
lstrip()左边删除(前边)
strip() 全部删除
但他们都是临时删除这个字符串的空白,所以删除后最好再存回变量中
py = "python " print(py.rstrip()) print(py) py_2 = " python" print(py_2.lstrip()) print(py_2) py_3 = " python " print(py_3.strip()) print(py_3) """ 输出结果为 'python' 'python ' 'python' ' python' 'python' ' python ' """
while循环
在这里跳过了些书本 简单的看了些 循环的格式
但经常会忘记 :冒号 包括if
留意循环体前面是4个空格
做了些简单的习题
count = 0 while count < 10 : count += 1 if count == 7: print(" ") continue print(count)
当时觉得这道题简单,反而想破头都没想出来。。2位大佬给了我2个解决方案
a = 0 i = 0 while i <100: i+=1 a+=i print(a)
print(sum(range(1,101)))
i = 0 while i <=100: i += 1 if i % 2 == 1: print(i)
i = 0 while i <= 100:
i += 1 if i % 2 == 0: print(i)
i = 0 k = 0 while i < 100: i += 1 if i_3 % 2 == 1: j = i else: j = -i k += j print(k)
count = 0 print("请注册用户名、密码") id = input('注册用户名:') password = input('注册密码:') while count <= 3: print("请输入用户名、密码") id_1 = input('登录用户名:') password_1 =input('登录密码:') if id == id_1 and password ==password_1 : print("登陆成功") exit() else: print("认证错误") count += 1 print("认证失败过多,请稍后再试")