Python编程-让繁琐的工作自动化(一)基础

本文详细介绍Python中的基本数学操作符、字符串操作、输入输出函数以及数据类型转换方法,包括print()、input()、len()函数的使用,和str()、int()、float()函数在不同数据类型间的转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本章重点:

1.+,-,*,/,//,%,** 是数学操作符,+和*是字符串操作符。

1.print()与 input()函数:输出与输入文本

print('hello world')
print("what is your name?")
my_name = input()
print('here your name is ',my_name)

hello world
what is your name?
bob
here your name is  bob

2.len()函数:返回一个整数,为传入字符串的长度,与C语言strlen类似。

print('len of \'hello word\' is' ,len('hello world') )
print('len of your name is', len(my_name))

len of 'hello word' is 11
len of your name is 3

3.str() 、int()和float()函数:传入其他类型的数值,得到字符串,整型或浮点型的值。

a = 25;
b = 'a'
c = 14.14

print('str(25)=' ,str(a))
#print(int(b)) #ValueError: invalid literal for int() with base 10: 'a'
print('float(25) =',float(a))
print('str(14.14)=',str(c))
print('int(14.14)=',int(14))

str(25)= 25
float(25) = 25.0
str(14.14)= 14.14
int(14.14)= 14

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值