码迷,mamicode.com
首页 > 编程语言 > 详细

python学习记录(持续更新)--最最最基础的一部分(变量、字符串、运算符)

时间:2020-02-25 17:49:56      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:打印   last   索引   换行   int   大写   math   出现   tty   

几个常用的函数

print 打印 

print(* * 10) =>  打印出10个*

input 获取输入

name = input(What is your name?)

int  float bool str 类型转换

num=int(‘12345‘)

 len upper lower  replace in 

course=Python for Beginners
print(len(course)) =>20
print(course.upper())=>PYTHON FOR BEGINNERS
print(course.lower())=> python for beginners
print(course.title())=> Python For Beginners 首字母大写
print(course)=>Python for Beginners upper 并不会更改原有字符串
print(course.find(‘P‘)) => 0 找到第一个出现的索引 区分大小写
print(course.replace(‘Beginners‘,‘Absolute Beginners‘)) =>Python for Absolute Beginners  替换字符

print(‘Python‘ in course)=> True 是否包含某字符串
 

 

几个细节

字符串输入的几种方式

print(‘ ‘)
print(" ")
print(‘‘‘  
这种可换行输入
很方便

‘‘‘)

  字符串索引

coutse=my name is Jay Chou
print(coutse[0])

=> m
print(coutse[-1])
=> u
coutse=‘myname is Jay Chou‘
print(coutse[0:3])
=>myn 从0开始算数3个字符打印
print(coutse[0:])
=>myname is Jay Chou 不指定结尾打印所有字符
print(coutse[:5])
=>mynam 开头不指定默认从0开始
coutse=‘myname is Jay Chou‘
another = coutse[:]
print(another)
=>myname is Jay Chou 用于clone字符串

格式化输入

first= Jay
last= Chou
msg = f{first}[{last}] is a coder
print(msg) =>Jay[Chou] is a coder

运算符

print(10/3) =>3.3333333333333335
print(10//3) =>3
print(10 % 3)=> 1
print((10**3)) =>1000 幂次运算
x = 10
x +=3
print(x) =>13

print(round(2.5)) => 2
print(round(2.51)) =>3 
round(80.23456, 2) :  80.23
round(100.000056, 3) :  100.0
round(-100.000056, 3) :  -100.0
print(abs(-2.5)) => 2.5 

运算函数模块 math


import  math 
print(math.ceil(2.1)) 天花板函数 向上取整 => 3
print(math.floor(2.1)) 向下取整 =>2


 

python学习记录(持续更新)--最最最基础的一部分(变量、字符串、运算符)

标签:打印   last   索引   换行   int   大写   math   出现   tty   

原文地址:https://www.cnblogs.com/dcxy/p/12362477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!