日循环

ID:21725 / 打印

日循环

pycache:

pycache 是由 python 创建的目录,用于存储 python 脚本的编译版本。这些文件具有 .pyc 扩展名,并在执行 python 脚本时自动生成。

*编程规则:*
1) 已知与未知
2)不要考虑整个输出
3)只考虑下一步
4)必要时引入变量
5) 密切观察节目

编写一个程序来打印 5 个连续的数字。

count = 1 if count<=5:     print(1, end=' ')     count=count+1 #count = 2 if count<=5:     print(1, end=' ')     count=count+1 # count = 3  if count<=5:     print(1, end=' ')     count=count+1 # count = 4  if count<=5:     print(1, end=' ')     count=count+1 # count = 5  if count<=5:     print(1, end=' ')     count=count+1 # count = 6 

if 语句,每次打印值 1 后跟一个空格 (end=' ') if count

1 1 1 1 1 

替代实现:

count = 1 while count <= 5:     print(1, end=' ')     count += 1 

如果目标是以更简洁的方式重复这个逻辑,可以使用循环

1 1 1 1 1 

多个 if 的简写形式被称为 while。

print() 函数使用两个可选参数 sep 和 end 来控制其输出的格式。

sep(分隔符):

指定插入到传递给 print() 的多个参数之间的字符串。

print("hello", "world", sep=", ") 
hello, world 
print("kuhan",'guru','varatha',sep='-') 
kuhan-guru-varatha 

结束(结束字符):
指定附加在输出末尾的字符串

print("hello", end="!") print("world")  
hello!world 

组合 sep 和 end:

print("python", "is", "fun", sep="-", end="!") 
python-is-fun! 

参数类型:

位置参数:

参数按照函数定义中指定的确切顺序传递。

def add(no1,no2):     print(no1+no2) add(10,20) 

这会调用函数 add,将 10 作为 no1 传递,将 20 作为 no2 传递。

30 

可变长度参数:

允许传递可变数量的参数。

如何从日期时间模块 python 中仅获取日期:

from datetime import date current_date=(date.today())  print("current date:",current_date) 
Current Date: 2024-11-25 
上一篇: 有关如何有效提示 Amazon Q 的提示
下一篇: Python&amp;#s Gradual Typing: Flexibly Enhancing Code Safety and Performance

作者:admin @ 24资源网   2025-01-14

本站所有软件、源码、文章均有网友提供,如有侵权联系308410122@qq.com

与本文相关文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。