当前位置: 首页 > news >正文

Python超入门(1)__迅速上手操作掌握Python

# 1.第一个代码:输出语句
# 1.第一个代码:输出语句
print("My dog's name is Huppy!")
print('o----')
print(' ||| ')
print("*" * 10)
"""
输出结果:
My dog's name is Huppy!
o----||| 
**********
"""
# 2.变量
# 2.变量
price = 10
rating = 7.7
name = 'Mosh'
is_True = True
print(price, rating, name, is_True)
"""
输出结果:
10 7.7 Mosh True
注意事项:
Python的变量不需要定义类型
Python严格区分大小写,True不能为小写
"""


练习:输出一个全名叫Ma Baoguo的成年人,年龄18岁,是一个新人

full_name = 'Ma Baoguo'
age = 18
is_new = Ture
# 3.接受与输入
name = input('What is your name? ')
print('My name is ' + name + '.')
"""
输出结果:
What is your name? CDNS
My name is CDNS
"""
练习:你的名字是什么?你住在哪里?
print('What is your name?')
name = input()
print('Where is your address?')
is_address = input()
print('My name is ' + name + '. My address is ' + is_address + '.')
# 4.型号转换
# 4.型号转换
birth_year = input('Birth year: ')  # birth_year是字符型
print(type(birth_year))  # 输出类型 :<class 'str'>
age = 2023 - int(birth_year)  # Python中的强制类型转换
print(type(int(birth_year)))  # <class 'int'>
print(age)
"""
输出结果:
Birth year: 2000
<class 'str'>
<class 'int'>
23
注意事项:
Python中的强制类型转换是:类型符(变量名)
Python输出语句中字符串不可与数字用 + 连接
"""
练习:输入一个重量(单位:磅)转换为(单位:千克),并输出
注意:1 kg 等于 0.45 lbs
weight_lbs = input('weight_lbs: ')
weight_kg = int(weight_lbs) * 0.45
# print("weight_kg: " + weight_kg)  # TypeError: can only concatenate str (not "float") to str
print("weight_kg: " + str(weight_kg))
print("weight_kg: ", weight_kg)
http://www.lryc.cn/news/158407.html

相关文章:

  • 后端面试话术集锦第 十四 篇:go语言面试话术
  • Oralce集群管理-19C RAC 私有网络调整为BOND1
  • 洛谷 Array 数论
  • 简明SQL条件查询指南:掌握WHERE实现数据筛选
  • 通过HbaseClient来写Phoenix表实现
  • uniapp qiun charts H5使用echarts的eopts配置不生效
  • 嵌入式Linux驱动开发(LCD屏幕专题)(三)
  • MySQL视图用户管理
  • 我发现了一个很好看的字体,霞鹜文楷!如何换windows和typora字体?
  • 微软8月系统更新引发问题:虚拟内存分页文件出现错误
  • swiper删除虚拟slide问题
  • FPGA实战小项目2
  • 一些关于完整小程序项目的优秀开源
  • Windows模拟器推荐
  • 搭建RabbitMQ消息服务,整合SpringBoot实现收发消息
  • Web framework-Gin(二)
  • 【聚类】K-Means聚类
  • 超图聚类论文阅读2:Last-step算法
  • React 防抖与节流用法
  • 发布 VectorTraits v1.0,它是 C# 下增强SIMD向量运算的类库
  • HCIA自学笔记01-冲突域
  • 3D封装技术发展
  • 探讨下live555用的编程设计模式
  • LeetCode 1123. Lowest Common Ancestor of Deepest Leaves【树,DFS,BFS,哈希表】1607
  • centroen 23版本换界面了
  • Postman 调用 Microsoft Graph API (InsCode AI 创作助手)
  • MySql 游标 触发器
  • 浅谈数据治理中的智能数据目录
  • 算法通关村第十七关:青铜挑战-贪心其实很简单
  • [Vue3 博物馆管理系统] 使用Vue3、Element-plus的Layout 布局构建组图文章