猫史档案馆


Python小经验(4)

用户:暗藏玄鸡暗藏玄鸡查看:0 回复:3 评论:0 创建时间:2022-08-30T16:09:55


许多人学会了python,好像什么都会,但真让你坐在电脑前编写像样的程序,可能只会一个print()函数了……那么我们来看看这个python最基本的代码:

print(‘Python’)    #输出字符串

 

print(‘12345’)    #输出数字

 

str=’Python’     #输出变量

print(str)

 

list=[1,2]        #输出列表

print(list)

 

t=(1,2)         #输出元组

print(t)

 

d={1,2}       #输出字典

print(d)

 

结果如下:

Python

12345

Python

[1,2]

(1,2)

{1,2}

 

是不是感觉到print()这个函数很神通广大?还有人问我字符串,列表,变量,元组,字典是什么意思?以后你的这些疑问会统统解开。咳咳!看蒙了没?我在说明一下。print()函数是将括号里的数据显示出来。语法:print(*objects,sep=’’end=’\n’,file=sys.stdout,flush=False)

Objects:表示复数,可以一次性输出多个项目。

Sep:表示我们可以使用sep分割多个对象。

End:结束符,后边跟着的是换行符/n;\n。

Fils:表示我们要写入的文件。

Flush:输出是否需要被缓存,后面常接false或者ture。

拓展:在Python,help()函数中,是这样解释print()函数的:Help on built-in function print in module builtins:

print(...)

print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

 

    Prints the values to a stream, or to sys.stdout by default.

    Optional keyword arguments:

    file:  a file-like object (stream); defaults to the current sys.stdout.

    sep:   string inserted between values, default a space.

    end:   string appended after the last value, default a newline.

    flush: whether to forcibly flush the stream.

这一个函数就到此为止,希望大家多多巩固。

如有错误,及时指正。


回复

上一页1 页 / 共 1下一页
#逸一时误一世##逸一时误一世#

print(‘12345’)    #输出数字

(其实你还是在输出字符串)

点赞0


评论


SCS_user_LoeheodVOQSCS_user_LoeheodVOQ

不是True和False吗

点赞1


评论


疯狂的ren疯狂的ren

print(type(__name__))

点赞0


评论