Python学习之路Day2
来源:互联网 发布:xperia x compact 知乎 编辑:程序博客网 时间:2024/05/16 09:54
**
1.变量的使用与赋值
**
message = "world!"print(message) #输出结果为:worldmessage = "hello world!" #输出结果为:hello worldprint(message)
**
2.字符串
**用引号(单/双引号)括起来的都是字符串
str1 = "This is a string"str2 = 'this is also a string'
2.1使用方法修改字符串的大小写
message = "hello worLd"print(message.title()) #title()方法,以首字母大写的方式显示每个单词print(message.upper()) #upper()方法,以所有字母大写的方式显示每个单词print(message.lower()) #lower()方法,以所有字母小写的方式显示每个单词
2.2合并字符串
first_name = "Zhang"second_name = "San"full_name = first_name + " "+second_nameprint(full_name) #打印结果为:Zhang San
2.2去除字符串首尾的空白(空格)
name = " Zhang San "print(name)print(name.rstrip()) #rstrip()删除字符串末尾的空格print(name.lstrip()) #lstrip()删除字符串首部的空格print(name.strip()) #strip()删除字符串首尾的空格
3.数字
python使用两个乘号表示乘方运算
print(4+4)print(9-1)print(16/2)print(4*2)print(2**3)#上述语句打印出来均为8,第三个,打印出来是8.0age = 23#python中要使数字与其他连接时,需强制转换str(age)将其转换为字符串类#型,否则报错message = "Happy" + str(age) + "rd Brithday"print(message)
阅读全文
1 0
- Python学习之路Day2
- python学习之路day2-循环
- python自动化之路-day2
- C++学习之路 day2
- Python学习笔记Day2
- Python学习,Day2
- python学习 day2
- python学习日志--day2
- python学习Day2
- python自动优化之路-day2.1
- Mysql学习之路——day2
- day2:第二天学习python
- Python爬虫学习笔记Day2
- DAY2之Python每日练习题
- python+Selenium2自动化之路Day2-pip降级selenium3.0
- Swift学习day2之Tuple
- java你好! 我的java学习之路 Day2
- 丹的Python学习笔记Day2复习
- hashcat之基于规则的攻击
- 吾家女婿看过来
- 安全防护工具之:Clair
- kali在高清屏幕下如何放大字体与图标
- 和客户沟通的总结
- Python学习之路Day2
- 打字游戏
- Android Studiod 的安装详情
- HDU 6046 hash (HASH, 2017 Multi-Univ Training Contest 2)
- netty学习五:websocket小demo
- 通达信行业、板块与自定义指数 (2015-09-01 17:58:00)
- sc2017新高二&高一模拟赛3 总结
- 关于跨域问题
- android使用Charles抓包https请求