1
hello_world='hello world'
print(hello_world)
执行整个脚本文件、以交互形式在控制台执行选中代码
变量名无需提前说明
注释、取消多行:ctrl+?、三引号间
2、缩进代码
机器学习=【‘决策树’,‘神经网络’,‘聚类分析’】
for i in 机器学习:
print(i)
print(‘hello’) #循环三次
print(‘hello’) #不是循环体,只打印一次
循环体要缩进、四个空格或者Tab键、同一级对齐
3、字符串基本操作
string1=‘python1’
string2=“python2”
string3='''1
python3
python4
2'''
print()
创建字符串可以用单引号、双引号、三引号,三引号可以无限换行(引号中有换行符)
#字符串的合并 string1+string2 得到 'python1python2'
#字符串的复制 string1*3 得到 'pythonpythonpython'
#字符串的转化 ,将字符串转化为数值 int(‘9’) 前提是字符串是由本身构成的,结果为9没有单引号
4、字符串的索引及切片
print(string1)
string1【0】 #正序索引
string1【-7】 #逆序索引
string1[【1:3】 #左闭右开、切片操作 得到‘yt’
string1[:3] #从0-2
string1【3:】 #从3到最后
5、任务实现-字符串与数值处理
#1.创建一个字符串变量“Apple's unit price is 9 yuan.”
applePriceString = "Apple's unit price is 9 yuan."
#2、提取出里面的数字9并赋值给新的变量
applePrice = applePriceString[-7]
#3、查看新变量的数据类型
type(applePrice)
#4、将提取出的数字9转成整形
applePriceInt=int(applePrice)
#5、确认数据类型是否转换成功
type(applePriceInt)
6、python常用运算符介绍
常用算数运算符
常用比较运算符
常用赋值运算符
常用逻辑运算符
成员运算符
身份运算符
运算符优先级排序
7、任务实现-计算圆形的各参数
#给定圆的半径,求圆的周长和面积
pi=3.14
r=3
c=2*pi*r
s=pi*r**2
#给定圆的周长,计算圆的半径和面积
c=5
r=c/(2*pi)
s=pi*r**2
#给定圆的面积,计算圆的半径和周长
s=5
r=(s/pi)**0.5
c=2*pi*r