python学习日志

Python学习日志1

6月15日
安装python
下载python 解释器 python 3.7

下载pycharm community edition, IDE

IDE基本设置
界面字体设置 settings , appearance
代码字体设置 settings , font

安装code editor = pycharm

1.创建一个新项目

create new a project ----->选择项目根目录和解释器版本----->create

2.新建文件并书写代码
3.完成代码并运行

注释:

注释的分类及用法
单行注释:#内容
多行注释:

“”"
注释1
注释2
注释3

“”"

creat page—>interpretor:python 3.8

第一个程序 print name
print(“Li Shushi”)

第二个程序 print a dog
print(‘o----’)
print(’ ||||’)

运行结果
Li Shushi
o----
||||

第三个程序 write an expression
print(’ 10)
运行结果


变量 :储存数据的时候当前数据所在的内存地址的名字
定义变量:
变量名 = 值 (先计算右边的值再赋值给左边的变量的 过程) 要满足标识符命名规则

标识符命名规则:
1.由下划线,数字,字母组成
2.不能由数字开头
3.不能使用内置关键字
4.严格区分大小写

第四个程序

name = ‘John Smith’ string 字符串变量
age = 20 integer 整数
height_m = 1.78 floating point 浮点型
is_new = True boolean 布尔值

输入变量 练习题1
name = input('what is your name? ')
color = input('what is your favorite color? ')
print(name + ’ likes ’ + color)
运行结果
what is your name? Li
what is your favorite color? blue
Li likes blue

第五个程序
要求:write a programm that will ask the year people born in, and then calculate the age and print it on the terminal

birth_year = input('insert your birth year: ')
print(type(birth_year))
age = 2020 - int(birth_year)
print(type(age))
print(‘you are currently ’ + str(age) + ’ years old!’)

运行结果
insert your birth year: 1990
<class ‘str’>
<class ‘int’>
you are currently 30 years old!

练习题2
Ask a user their weight (in pounds) , convert it to kilograms and print on the terminal

weight_pounds = input('insert your weight: ')
weight_kg = (453.59237 * float(weight_pounds) )/ 1000
print('your weight in kg is: ’ + str(weight_kg))

运行结果
insert your weight: 100
your weight in kg is: 45.359237

总结:1.不考虑字符串本身存在引用的情况,单引号和双引号功能基本相同,引用整段话用三引号。
2. 在运行一个 expression 时, python会先尝试获得这个expression的结果值。
3. 四种变量类型: 字符串(string)整型(integer)
浮点型(float) 布尔值(boolean)
4. 编写程序时应特别注意变量的类型,否则会导致程序不能运行,如
a. print()中的 + 只能连接 str 型 ,
b. 要进行数学运算需先转化为 int 或 float 型
5.变量转换:
str() int() 等

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值