青少年叛逆
青少年叛逆
IT培训
广告招商

Python基础语句有哪些?老男孩Python培训学校

 在学习或者工作中,通过Python进行编码的时候,经常会用到一些常用的句式,也就是所谓的基础语句。它们出现的频繁非常高,也是约定俗成的写法。那么Python最常用的基础语句有哪些?本文为大家简单介绍几个,看看你了解多少。

  1、format字符串格式化

  format把字符串当成一个模板,通过传入的参数进行格式化,非常实用且强大。

  # 格式化字符串

  print('{}{}'.format('hello','world'))

  # 浮点数

  float1 = 563.78453

  print("{:5.2f}".format(float1))

  2、连接字符串

  使用+连接两个字符串

  string1 = 'linux'

  string2 = 'hint'

  joined_string = string1 +string2

  print(joined_string)

  3、if...else条件语句

  Python条件语句是通过一条或多条语句的执行结果来决定执行的代码块。其中if...else语句用来执行需要判断的情形。

  # Assign a numeric value

  number = 70

  # Check the is more than 70 or not

  if(number >= 70):

  print("You have passed")

  else:

  print("You have note passed")

  4、for...in\while循环语句

  循环语句就是遍历一个序列,循环去执行某个操作,Python中的循环语句有for和while。

  for循环

  # Initialize the list

  weekdays =
["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]

  print("Seven Weekdays are:n")

  # Iterate the list using for loop

  for day in range(len(weekdays)):

  print(weekdays[day])

  while循环

  # Initialize counter

  counter = 1

  # Inerate the loop 5 times

  while counter < 6:

  #print the counter value

  print("The current counter value:%d" % counter)

  # Increment the counter

  counter = counter + 1

  老男孩教育是Python培训领域的专家,2012年就开展了Python培训,是行业较早的Python培训机构,积累了大量的Python培训教学经验,并能全局把控企业用人指标,科学的制定Python教学课程体系,满足5-8年职业生涯需求,让学员轻松拿下高薪职位!

注意:吐槽知乎网只是一个问答与文章免费发布平台,所有信息均有会员免费发布,不产生金钱交易,如果你有资金往来,请及时通过电话与对方联系,调查清楚,确认无误在选择,否则造成你的损失,由自己承担,本平台概不负责,谢谢!

0 个评论

要回复文章请先登录注册

狗粮批发
嘿,进入会员专区!