Python Masterclass and get certified

Welcome to course on python.Please ensure to follow every steps in the course correctly

Getting Started With Python 3

Python is a general-purpose programming language that is becoming ever more popular for data science. Companies worldwide are using Python to harvest insights from their data and gain a competitive edge. Start space academy’s online Python course now.

Hello World Using Python

Just to give you a little excitement about Python, We are going to give you a small conventional Python Hello World program, You can try it by clicking the Run Button.

 

Code:

print (“Hello World”);

Add Your Heading Text Here

Example

Now type “your name” instead of “Hello World” and run the code

1) Clear the existing codes in the programming console (ie main.py)


2) Enter the below code and click run.(Please enter your name in the code instead of your name in the below code )

Code:

print (“your name”);

Add Your Heading Text Here

Comments In Python

A hash sign (#) that is not inside a string literal begins a comment. All characters after the # and up to the end of the physical line are part of the comment and the Python interpreter ignores them.


1) Please clear the current code in main.py and enter the below code.


2)Type this Code and Run it:

print (“Hello, Python!”); #my comment


3)Click the Run button to see the output

 

Now we understood that the comments wont appear in the output and it can be used by the programmer to identify certain parts of code while coding 


Add Your Heading Text Here

Python Variables

A variable is a named location used to store data in the memory. It is helpful to think of variables as a container that holds data that can be changed later in the program.

 

Assigning Values To Variables In Python

you can use the assignment operator “=" to assign a value to a variable.

Example 1: Declaring and assigning value to a variable

1) Clear the line existing codes in the programming console(ie main.py)

2) Enter the below code and run it, you will find that the assigned value appears in the output ie “spacefoundation.com”

website = "spacefoundations.com"
print(website)

Add Your Heading Text Here

Example 2: Changing the value of a variable

1) Clear the line existing codes in the programming console(ie main.py)

2) Enter the below code and run it 

website = "spacefoundations.com"
print(website)

# assigning a new variable to website
website = "spaceplatforms.in"

print(website)

In the above program, we have assigned spacefoundations.com to the website variable initially. Then, the value is changed to spaceplatforms.in

Add Your Heading Text Here

Example 3: Assigning multiple values to multiple variables

1) Clear the line existing codes in the programming console(ie main.py)

 

2) Now enter the below code and run it

a, b, c = 5, 3.2, "Hello"

print (a)
print (b)
print (c)

3) Now let’s see what happens if we only print one variable…For that enter the code below and run it

a, b, c = 5, 3.2, "Hello"

print (a)

Add Your Heading Text Here

List In Python

List is an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. All the items in a list do not need to be of the same type.

Declaring a list is pretty straight forward. Items separated by commas are enclosed within brackets [ ]

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

a = [1, 2, 3]
print(a)

We can use the slicing operator [ ] to extract an item or a range of items from a list.

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

a = [1,2,3,4,5,6,7,8]

print("a[2] = ", a[2])

print("a[0:3] = ", a[0:3])

print("a[5:] = ", a[5:])

Add Your Heading Text Here

Python Strings

String is sequence of Unicode characters. We can use single quotes or double quotes to represent strings. Multi-line strings can be denoted using triple quotes, ''' or """.

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

 

s = "Hello World,This is a string"
print(s)
s = '''This is a multiline
string'''
print(s)

Add Your Heading Text Here

Python Set

Set is an unordered collection of unique items. Set is defined by values separated by comma inside braces { }. Items in a set are not ordered.

1) Clear the line existing codes in the programming console(ie main.py)

2) Enter the below code and run it 

a = {4,1,5,2,3}

# printing set variable
print("a = ", a)

# data type of variable a
print(type(a))

We can perform set operations like union, intersection on two sets. Sets have unique values. They eliminate duplicates.

a = {1,2,2,3,3,3}
print(a)

Add Your Heading Text Here

Arithmetic Operators In Python

Operators are special symbols in Python that carry out arithmetic or logical computation. The value that the operator operates on is called the operand.

 

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

x = 25
y = 15

# Output: x + y = 40
print('x + y =',x+y) # Output: x - y = 10 print('x - y =',x-y) # Output: x * y = 375 print('x * y =',x*y) # Output: x / y = 1.66 print('x / y =',x/y)

Add Your Heading Text Here

Addition Using Python

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

 
x = 25
y = 15

print('x + y =',x+y)

Add Your Heading Text Here

Subtraction Using Python

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

x = 25
y = 15

print('x - y =',x-y)

Add Your Heading Text Here

Multiplication Using Python

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

 
x = 25
y = 15

print('x * y =',x*y)

Add Your Heading Text Here

Division Using Python

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

x = 25
y = 15

print('x / y =',x/y)

You will get the output answer as 1.66

Add Your Heading Text Here

Comparison Operators In Python

1) Clear the line existing codes in the programming console(ie main.py)

2) Enter the below code and run it 

x = 5
y = 10

# Output: x > y is False print('x > y is',x>y) # Output: x < y is True print('x < y is',x<y) # Output: x == y is False print('x == y is',x==y) # Output: x != y is True print('x != y is',x!=y) # Output: x >= y is False print('x >= y is',x>=y) # Output: x <= y is True print('x <= y is',x<=y)

Output:

x > y is False
x < y is True
x == y is False
x != y is True
x >= y is False
x <= y is True

SPASpace SPACE

If Statement In Python

If statements are control flow statements which helps us to run a particular code only when a certain condition is satisfied. For example, you want to print a message on the screen only when a condition is true then you can use if statement to accomplish this in programming.

Example:

 

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

flag = True
if flag==True:
    print("Welcome")
    print("To")
    print("Space")

Add Your Heading Text Here

Output:

Welcome
To
Space

In the above example we are checking the value of flag variable and if the value is True then we are executing few print statements. The important point to note here is that even if we do not compare the value of flag with the ‘True’ and simply put ‘flag’ in place of condition, the code would run just fine so the better way to write the above code would be:

Example:

 

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

flag = True
if flag:
    print("Welcome")
    print("To")
    print("Space")

Add Your Heading Text Here

By seeing this we can understand how if statement works. The output of the condition would either be true or false. If the outcome of condition is true then the statements inside body of ‘if’ executes, however if the outcome of condition is false then the statements inside ‘if’ are skipped. Lets take another example to understand this:

 

Example:

 

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

flag = False
if flag:
    print("You")
    print("are")
    print("Awesome")

Add Your Heading Text Here

The output of this code is none, it does not print anything because the outcome of condition is ‘false’.

Python if example without boolean variables

Example:

 

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

num = 100
if num < 200:
    print("num is less than 200")

Output:

num is less than 200

Add Your Heading Text Here

If Else Statement In Python

We use if statements when we need to execute a certain block of Python code when a particular condition is true. If..else statements are like extension of ‘if’ statements, with the help of if..else we can execute certain statements if condition is true and a different set of statements if condition is false. For example, you want to print ‘even number’ if the number is even and ‘odd number’ if the number is not even, we can accomplish this with the help of if..else statement.

 

Example:

 

1) Clear the line existing codes in the programming console(ie main.py)

2) Now enter the below code and run it

num = 22
if num % 2 == 0:
    print("Even Number")
else:
    print("Odd Number")

Add Your Heading Text Here

Output:

Even Number

Brain Teaser

1) Write a code to print Welcome to Earth in python.

2) Add 24+35 in python

3) Write a code to find whether 856 is even, If yes print Bingo in the output

 

Try these yourselves. All the best

Add Your Heading Text Here

Congratulations

You have completed the course, Now take the test and get certified.

Privacy

Our Services

Scientific Platforms & Cosmic Explorations
© Copyright 2021 SPACE - All Rights Reserved