Python语法基础学习_变量和简单数据类型

  • 变量和简单数据类型
print(message)
# 变量的使用规则
# 只能包含数字 字母 下划线 且开头不能够是数字 ,变量名不能够包含空格,不可以是关键字和函数名
  • 字符串
# 字符串
# 用单引号或者是双引号包括起来的就是字符串 使用比较灵活
test='this is  a string'
test2="this is a String"
test3="this is 'a' String"
test4='this is "a" String'
print(test+'\n'+test2+'\n'+test3+'\n'+test4)


# 字符串函数
test5='naMe aBc'
print(test5.title()) #将字符串的单词的第一个字母大写,其他小写
print(test5.upper())
print(test5.lower())


# 合并字符串
firstName= 'xiao'
lastName= 'Li'
print(firstName+" "+lastName)


# 去掉字符串的空白
test6=' Python '
print(test6.rstrip()) #去掉右端也就是尾部的空格
print(test6.lstrip()) #去掉左端也就是尾部的空格
print(test6.strip()) #去掉两段的空格

打印结果

  • 整数
# 整数
# 加减乘除
print(2+3)
print(3-2)
print(3*2)
print(3/2)


print(3**3) #乘方是用两个* 表示


# 在字符串和整数一起使用时候要用str() 函数转换类型
age=20
print("my age is "+str(age))

打印结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值