Discord Server Red Security Twitter Donation to Red Security Red Security Youtube Channel Red Security Tumblr Profile
Login or Register to Hide ads and Accessing all features on the forum

Tutorial 

Python 2: Basic Concepts

2 Replies, 1139 Views

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"
Love me like you do Heart
(This post was last modified: 04-17-2022, 12:51 AM by Covid-19.)
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.
(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
Love me like you do Heart

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tutorial Doubly Linked List in Python Covid-19 0 2,227 07-30-2022, 09:15 PM
Last Post: Covid-19
  Tutorial Linked List in Python Covid-19 2 2,606 07-30-2022, 08:25 PM
Last Post: Covid-19
  Tutorial File Handling in Python Covid-19 2 2,644 06-16-2022, 06:17 PM
Last Post: Covid-19
  Tutorial Exceptions in Python Covid-19 0 1,822 06-08-2022, 09:19 PM
Last Post: Covid-19
  Free Automate the boring stuff with Python Covid-19 0 1,589 06-07-2022, 06:58 PM
Last Post: Covid-19
  Tutorial Turtle in Python Covid-19 0 1,820 06-02-2022, 10:14 PM
Last Post: Covid-19
  Tutorial Python 3.5: Class Methods Covid-19 0 1,770 05-29-2022, 01:07 PM
Last Post: Covid-19
  Tutorial Python 3.2: Inheritance in Python Covid-19 2 2,800 05-27-2022, 06:47 PM
Last Post: Covid-19
  Tutorial Python 3.4: Encapsulation and Abstraction Covid-19 0 1,803 05-27-2022, 06:45 PM
Last Post: Covid-19
  Tutorial Python 3.3: Operator Overloading Covid-19 2 2,797 05-26-2022, 08:50 PM
Last Post: Covid-19



Users browsing this thread: 1 Guest(s)