Red Security
Tutorial Python 2: Basic Concepts - Printable Version

+- Red Security (https://redsecurity.info/cc)
+-- Forum: Programming (https://redsecurity.info/cc/forumdisplay.php?fid=5)
+--- Forum: Python (https://redsecurity.info/cc/forumdisplay.php?fid=9)
+--- Thread: Tutorial Python 2: Basic Concepts (/showthread.php?tid=7879)



Python 2: Basic Concepts - Covid-19 - 04-15-2022

Basic Concepts:

Our first Program in Python:
Let’s Start making our first program in Python.  We will write a program that prints “Hello World" on the screen So let’s get in and write our first Python program. You can use any IDE for python for offline work. I suggest the ‘Anaconda’ python interpreter. And for online I suggest Replit (https://replit.com) so just go to this website and create your first program. Without taking any longer Let’s get started..

Code:
print(“Hello World !”)


Output: Hello World !

So as you can see it is so simple and it will print Whatever you write in between these double quotations , you can also use single quotations. It doesn’t matter if it will work the same. Let’s do something more,

Code:
print(“Hello World!”)
print (“I am Covid-19”)

Output: Hello World
             I am Covid-19

It will print these two statements on different lines and it will automatically generate a new line.
What if you want to print two or more lines in one print function (We will cover functions later)?
So here is the answer: just put ‘\n’ where you want to break the line. Let's code it.


Code:
print(“Hello World!\nI love Python”)

Output: Hello World!
            I Love Python

And what if you want to print double quotation (“”) or single (‘’) on your screen?
You can print it just by adding a backslash (\) before it let’s see how it works

Code:
print(“I\’m Covid, I\’m here to teach you Python”)

Output: I’m Covid, I’m here to teach you Python
 
The interpreter will not print the backslash.
So, there is a task for use guys.
Code:
print("* ** *** ****")
 
you have to make this triangle correct output should be like this.
*
**
***
****
Key point:
Anything written in these double quotations is known as strings we will cover it in coming tutorials.
In the next post we will cover some basic operations...
("Allah Hafiz" and "Good Bye" Till the next post )
"Keep Learning and Keep exploring"



RE: Python 2: Basic Concepts - Tbone - 05-21-2022

When I typed print(“I\’m Covid, I\’m here to teach you Python”) in Replit it returned a syntax error and I don't know why
Also, print("* ** *** ****") output had the asterisks in a straight line instead of a triangle as shown in the example.


RE: Python 2: Basic Concepts - Covid-19 - 05-21-2022

(05-21-2022, 01:27 PM)Tbone Wrote: When I typed print(“I\’m Covid, I\’m here to teach you Python”) in Replit it returned a syntax error and I don't know why
Also, print("* ** *** ****") output had the asterisks in a straight line instead of a triangle as shown in the example.

in first statement remove the double quotes and single quotes and type it again in your interpreter it will fix it. and for the second problem i said that it is to do task you have to make it print like a triangle as shown in output this is some sort of test for you. and if you are still having this issue you can ask me anytime
Thank you