Python3.5开发2 - 集成开发环境搭建

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiang12835/article/details/82753585

Python3.5开发2 - 集成开发环境搭建

Python3可以使用中文作为变量

字符拼接 +

知识点:

  • 安装与配置Pycharm

  • 调试Python程序

  • 变量

演示:


a = "hello %s" % 'yx'

b = '你好{},今天{},星期二{}'.format('yx',123,'ddd')

ab = a + b

print(ab)


c = 'hello "yx"'

d = "hello 'yx'"

e = 'hello \''

print(e)

import random


a = random.randint(100,10000)

print(a)

作业:格式化秒数的小工具

使用format和+

import random



num = random.randint(100,10000)

hour = int(num/3600)

minute = num%3600//60

second = num%3600%60



result1 = "使用format打印:{}秒 = {}时{}分{}秒".format(num,hour,minute,second)

result2 = "使用字符串拼接打印:" + str(num) + "秒 = " + str(hour) + "时" + str(minute) + "分" + str(second) + "秒"

print(result1)

print(result2)

猜你喜欢

转载自blog.csdn.net/xiang12835/article/details/82753585