Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22851

IslandT: Python Tutorial — Chapter 2

$
0
0

In this chapter, I am going to go through three subjects, 1) The Python print method 2) Python Indentation 3) Python comment.

Python Print Method

Python print method will print a word or phrase which contains within the ” ” on the screen, for example, try this out in your PowerShell console…

print("Good Morning People!")

This will do it, the above phrase will get printed on the screen of the console after you have hit the enter key on your Laptop! Just one line of code, that is all! The print method comes with the standard Python modules thus there is no need to import the extra modules into your Python file, you can use that print method right away!

Python Indentation

Python takes indentation very seriously because it uses indentation to indicate a block of code. You can use any number of spaces to indent your code but make sure the code within the same block needs to be indented with the same number of spaces.

i = 0
while i < 2:
   print("hi")
   i += 1

Python Comment

The user of your module needs to know what each line of the code does thus comment is very important. Here is an example of a comment.

# Hello Man
print("Hello Boy!")

The phrase after # is the comment but the code below it is not because the comment will just extend until the end of the first line but will not get into the second line!


Viewing all articles
Browse latest Browse all 22851

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>