Lesson 1: Python Basics
1.2 Installing Python
Python can be installed from python.org. IDEs like VS Code, PyCharm, or Jupyter Notebook can be used for coding.
Explanation:-
No code for this topic.1.3 Hello World
The first program prints text to the screen using the print() function.
print("Hello World")
Explanation:-
print() outputs the text "Hello World" to the console.# Alternative print example
print("Hi there!")
Explanation:-
Alternative way to print a message.1.4 Python Comments
Comments are used to explain code and are ignored by the interpreter.
# This is a comment
print("Hello")
Explanation:-
Lines starting with # are ignored. Only print("Hello") executes.# Multi-line comment
"""
This is a comment
"""
Explanation:-
Alternative way to write multi-line comment.1.5 Variables
Variables store data values and can be named anything following Python naming rules.
x = 10
y = "Kapil"
print(x, y)
Explanation:-
x stores integer 10, y stores string "Kapil". print() displays both values.z = 3.14
print(z)
Explanation:-
z stores float value 3.14.1.6 Data Types
Python supports different data types like int, float, string, list, tuple, set, dictionary, etc.
x = 5
y = 3.14
name = "Kapil"
Explanation:-
int, float, and string examples.nums = [1,2,3,4]
Explanation:-
A list example.1.7 Type Conversion
Convert one data type to another using int(), float(), str(), etc.
x = int(3.14)
print(x)
Explanation:-
Float 3.14 converted to int 3.y = str(100)
print(y)
Explanation:-
Integer 100 converted to string "100".1.8 Operators
Python supports arithmetic, comparison, logical, assignment, and bitwise operators.
a = 5
b = 2
print(a+b, a-b, a*b, a/b)
Explanation:-
Arithmetic operations example.print(a==b, a!=b, a>b, a<b)
Explanation:-
Comparison operations example.1.9 Conditional Statements
Use if, elif, and else to execute code based on conditions.
x = 10
if x>5:
print("Greater than 5")
Explanation:-
Simple if statement example.x = 2
if x>5:
print("Yes")
else:
print("No")
Explanation:-
If-else statement example.1.10 Loops - for & while
Loops allow you to execute code multiple times.
for i in range(5):
print(i)
Explanation:-
For loop example.i=0
while i<5:
print(i)
i+=1
Explanation:-
While loop example.1.11 Quiz - Python Basics
Test your understanding of Python basics.
Comments (3)
Login to comment
addkee: hi
addkee: nice course
addkee: superb course