python学习日志--简单基础

print以及类型转化

print('hello world')
#**********
print("*"*10)
#变量的使用
price=10
#the price:10
print("the price:"+str(price))
name='moshi'
#首字母要大写
flag=True
rating=4.9
#moshi	True	4.9
print(name+"\t"+str(flag)+"\t"+str(rating))
#input
name=input("write your name:"+" \t")
print("the name:"+name)
#强制转化
print(int('1092'))
real=input('the age of you: ')
age=2020-int(real)
print("the age:"+str(age))
msg='''
hello ashlkdjhaslkjf
adfsglhjksadg
fsdalkjhfglsadk
'''
print(msg)

字符串以及格式化字符

msg='hello world'
#l   r
print(msg[3]+"\t"+msg[-3])
#hel
print(msg[0:3])
#hello world
print(msg[0:])
#hello wo
print(msg[:-3])
#格式化字符   f''
#python的print字符串前面加f表示格式化字符串,
#加f后可以在字符串里面使用用花括号括起来的变量和表达式,
#如果字符串里面没有表达式,那么前面加不加f输出应该都一样.
#Python3.6新增了一种f-字符串格式化
#格式化的字符串文字前缀为’f’和接受的格式字符串相似str.format()。
# 它们包含由花括号包围的替换区域。替换字段是表达式,在运行时进行评估,然后使用format()协议进行格式化。
#formatted string literals, 以 f 开头,包含的{}表达式在程序运行时会被表达式的值代替。
first='john'
last='smith'
msg=f'{first} [{last}]'
print(msg)

字符串方法

course="s  adfadsSSSS"
print(len(course))
print(course.upper()+"\t"+course.lower())
print(course.find('fa'))
print(course.find('SSSS'))
print(course.replace('SSSS','asudhasku'))
print('a' in course)
print(course.title())

运算符以及math

1267650600228229401496703205376
print(2**100)
50.0
print(100/2)
1
print(3%2)
9.899999999999999
print(3.3*(3))
9.9
print((3.3*10000)*(3*10)/100000)

from decimal import *
a=Decimal(3)
b=Decimal(3.3)
9.899999999999999467092948180
print(a*b)
a=Decimal('3')
b=Decimal('3.3')
9.9
print(a*b)
3
print(round(3.3))
3.3
print(abs(-3.3))

import  math as mh
4
print(mh.ceil(3.3))
3
print(mh.floor(3.3))

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值