Table of Contents
First Steps with Python
Display Print Text!
print("Hello World!")
Extension – fileName.py
Comments in python
# This is a comment, it starts with a hash/pound sign
Variables in Python
You don’t need to define a variable type in python, in the below case, a is an integer, b is float, c is a string, d is boolean and e is special None Type Variable
# Variables in Python
a = 25
b = 2.8
c = "Hello World!"
d = true
e = None
Running python files in the terminal –
python hello.py
#or
python3 hello.py
Formatted Strings
name = input("What is your name? ")
print(f"Hello, {name}")
Conditions in Python
Create a new file conditions.py and add the following code to the file
Run with python conditions.py
number = int(input("Number :"))
if number > 0:
print("Number is positive")
elif number < 0:
print("Number is negative")
else:
print("Number is not Zero")
Sequences
name = "Anirudh";
print(name[0]);
# output: A
print(name[1])
# output: n
names = ["Ani", "Mike", "Steve"]
print(names[0])
#output: Ani
Data Structures
- list – sequence of mutable values (values can be modified)
- tuple – sequence of immutable values (values cant be modified)
- set – collection of unique values
- dict – collection of key-value pairs