【python学习】第一章 变量与简单数据类型

# _*_ coding:utf-8 _*_
"""
name:zhangxingzai
date:2022/10/24
"""


# 数据类型-字符串string
print('Hello World')

# 赋值变量输出
massage = 'hello WORLD'
print(massage)

# 修改字符串的大小写
print(massage.title())  # 首字母大写
print(massage.upper())  # 全部大写
print(massage.lower())  # 全部小写

# 字符串的拼接
first_name = 'hello'
last_name = 'world'
full_name = first_name + last_name
print(full_name)
# 也可以用{}中加变量表示为变量值
full_name1 = f"{first_name} {last_name}"  # f语法是python3.6引入的,之前的版本需要使用方法format(),例:{}{}.format(first_name,last_name)
print(full_name1)

# 字符串拼接&修改字符串
print(f"Python3,{full_name1.title()}!")

# 制表符与换行符
print('hello \tworld')
print('hello \nworld')
print('Languages: \n\tpython \n\tC \n\tJava')

# 删除字符串中的空白
massage1 = ' python3 '
print(massage1.rstrip())  # 去掉字符串末尾的空白
print(massage1.lstrip())  # 去掉字符串开头的空白
print(massage1.strip())   # 去掉字符串两头的空白
print(massage1)

# 数据类型-整数int  + - * / ()运算
print(1 + 2)
print(3 - 2)
print(3 * 2)
print(2 / 2)
print((1 + 2) * 3)
print(2 ** 3)

# 数据类型-浮点数float
print(1 + 2.0)
print(0.22 * 0.22)
print(int(0.2 * 6))

# 数字中的下划线,给数字分组,方便阅读,不打印
money = 1_000_000_000
print(money)

# 同时给多个变量赋值
a, b, c = 1, 2, 3

# python之禅
import this

# python用#注释,多行注释是选中要注释的行ctrl + / ;取消一样

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小胖虎*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值