print function in python

Learn Python with Aswin (25 Part Series)

1 Python Programming: A Beginner’s Guide
2 Hello, world!
21 more parts…
3 Data types in Python
4 Variables in Python
5 Getting input in python
6 print function in python
7 Arithmetic Operators in Python
8 Bitwise Operators in python
9 Comparison Operators in python
10 Assignment Operators in python
11 Logical Operators in python
12 Identity Operators in python
13 Membership Operators in python
14 Conditional statements in python
15 Loops in python
16 Basic jump statements in python
17 Else Clauses on Loops
18 pass statement in python
19 functions in python
20 the return statement in functions
21 Arguments and parameters in functions
22 Functional programming in python
23 Lambda expressions in python
24 Complete Python Developer
25 What is a Programming Language?

print() function and input() function makes the program more interactive with the user.

Although, there are some extra things we can do with print() which makes the output formattable.

Functionalities of print() function

  • Let’s start with the syntax: print(object(s), sep=separator, end=end, file=file, flush=flush)
  • Fact: In python, all data types are implemented as an object.
  • object(s): Will accepts any number of objects, which will be converted into a string before printed. We can pass it in two way:
  • Concatenated:
  • Comma seperated: Output:
Enter any number: 2021
year:2021

Enter fullscreen mode Exit fullscreen mode

  • sep=’separator’: This is Optional. Used to specify how to separate the objects, if there is more than one. Default is ‘ ‘ (space). Output:
Enter any number: 2021
year:   2021

Enter fullscreen mode Exit fullscreen mode

  • end=’end’: This is Optional. Used to specify what to print at the end. Default is ‘\n’ (new line). Output:
Enter any number: 2021
year: 2021  month: Jan

Enter fullscreen mode Exit fullscreen mode

  • file: This is Optional. Default is sys.stdout. Used to specify the name of the file to write the output. If the file doesn’t exist, it will create a new file. Output (in ‘Greetings.txt’ file):
!!! Wish you a happy new year   !!!
Enjoy the year--->2021---> and the month --->January

Enter fullscreen mode Exit fullscreen mode

Best Resources

Who Am I?

I’m Aswin Barath, a Software Engineering Nerd who loves building Web Applications, now sharing my knowledge through Blogging during the busy time of my freelancing work life. Here’s the link to all of my socials categorized by platforms under one place: https://linktr.ee/AswinBarath

Thank you so much for reading my blog.

Learn Python with Aswin (25 Part Series)

1 Python Programming: A Beginner’s Guide
2 Hello, world!
21 more parts…
3 Data types in Python
4 Variables in Python
5 Getting input in python
6 print function in python
7 Arithmetic Operators in Python
8 Bitwise Operators in python
9 Comparison Operators in python
10 Assignment Operators in python
11 Logical Operators in python
12 Identity Operators in python
13 Membership Operators in python
14 Conditional statements in python
15 Loops in python
16 Basic jump statements in python
17 Else Clauses on Loops
18 pass statement in python
19 functions in python
20 the return statement in functions
21 Arguments and parameters in functions
22 Functional programming in python
23 Lambda expressions in python
24 Complete Python Developer
25 What is a Programming Language?

原文链接:print function in python

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
The world is like a mirror: Frown at itand it frowns at you; smile, and it smiles too.
世界犹如一面镜子:朝它皱眉它就朝你皱眉,朝它微笑它也吵你微笑
评论 抢沙发

请登录后发表评论

    暂无评论内容