python笔记-001-基础(字符串和数值)

# 输出函数
print("hello world...")

# 变量定义
# 变量名只能包含字母、数字、下划线,不能以数字打头
msg = "hello python world..."
print(msg)

# 字符串:用引号括起的都是字符串(单引号、双引号)
# 灵活性:字符串可包含单引号或双引号
msg = 'I told my firend,"Python id my favorite language!"'
print(msg)
msg = "The language 'python' is named after Monty Python."
print(msg)

# 字符串每个单词首字母大写:aaa.title()
msg = "hello world..."
print(msg.title())

# ★字符串大小写处理:aaa.upper()aaa.lower()
print(msg.upper())
print(msg.lower())

# 拼接字符串
first_name = "san"
last_name = "zhang"
full_name = first_name + " " + last_name
print("Hello," + full_name + ".")
print("Hello," + full_name.title() + ".")

# 制表符:\t
print("*Hello\tWorld*")
# 换行符:\n
print("*Hello\nWorld*")

# ★删除字符串首尾空白
msg = "  python  "
# 去首:aaa.lstrip()
print(msg.lstrip())
# 去尾:aaa.rstrip()
print(msg.rstrip())
# 去两端:aaa.strip()
print(msg.strip())

# 数值
# 加(+)、减(-)、乘(*)、除(/)
# ★乘方(**)
print(3 ** 2)
# 浮点数
print(0.2 + 2)
# ★输出类型错误解决方案:数值转字符串str(aaa)
msg = 3 ** 2
print("3 ^ 2 = " + str(msg))
msg = 2017
print("今年是 " + str(msg) + " 年.")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值