Python 变量类型和运算符

本文介绍了Python中if语句的基本用法及其注意事项,并通过示例展示了如何使用if语句进行条件判断。此外,还讲解了字符串的简单运算方法,如字符串重复等。

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

-*- coding:utf-8 -*-

'''
if语法

if conditon:
[tab键] command
[tab键] command
...
else:
[tab键] command
[tab键] command
...


'''

age = input("age :")
#input()获取的所有数据都是字符串类型

#数据的类型转换

#int()函数将参数传化成整形
age_num = int(age)

#if age>18:    ---age实际上是字符串类型,无法与18这个整形数值进行比较,python解析器将会报错
if age_num>18:
        print("i can go to shanghai .")
else:
        print("i still insist .")


#字符串的运算
ch= "h"
chs = ch * 10

#将会打印10个h
print("result is %s"%chs)

str = "hello"
strs = str * 10

#将会打印10个hello
print("result is %s"%strs)


#print()函数多变量输出
addr = "shanghai"
phone = 110
print("addr is %s , phone is %d ."%(addr,phone));

转载于:https://www.cnblogs.com/zhanggaofeng/p/9217453.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值