S
0
- Joined
- Aug 20, 2022
- Messages
- 61
- Reaction score
- 3
- Points
- 8
- Age
- 25
- Location
- Philippines
- grants
- ₲264
2 years of service
Thank you
thank you for thisHello guys, I started a basic tutorial serious on Python . Hear I'm going to explain many theoretical and practical stuff in python programming. I'll explain basic things and also some deep stuff like object oriented programming, Ctypes, Network programming etc.
Printing is an absolutely basic part of a programming language. We learned how we can print a string with PHP and C. So in this tutorial we are going to talk about python printing. Hear I explain you both python 2 and 3. Let's see following program.
[size=small] First thing to understand is syntax of printing something. print ('string goes hear') We can use print() function to do this. You want to put the string as the argument for that function. (I'll explain more about functions in a later tutorial). What if you include a quot in your string? It will disturb Python's syntax.
[/size]
[size=small][size=small][size=small]Code:
[/size][/size][/size]
In next line I opened a nano editor and corrected the error. After I ran it again and its working fine. So what the magic happened hear when we used a backward slash? Its a escape symbol. That mean when python interpreter see a backward slash it'll ignore next character. Actually this is not a ignoring. It think next character is a specific one and should not printed normally. Also there are some other escape characters . We use those sometimes in our programs. \n - This one is used to indicate a line break. If we use this between a string it will break and go to another line. \t - This acts as a tab space. \\ - We can print a backward slash with this. Why it happen?? Think.! Now you need to do experiments with those. Do it yourself. Next we have another problem. This string also uses a quote inside it. But it's not produce an error. print ("this code's syntax is OK. But why?") This is because hear we have used different quotation marks for indicate the string. If we want to make a comment we use '#' symbol. In a previous tutorial I have explained you why we use comments in our programs. Also we can use triple quotes for a multi line code. This is very helpful when we want to disable a code block for debugging purpose.
Code:
Finally I have listed another way to print a string. Hear we don't use parentheses. But this way is not correct in python 3.x version.
Code:
[size=small][size=small]So it's a good programming practice to always use first method for python printing. Because it's important to learn both versions of python.
[/size][/size]