Python 变量类型和运算符

-*- 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));

posted on 2018-06-23 16:02  寒魔影  阅读(163)  评论(0编辑  收藏  举报

导航