Discover the Basics of Python: A Comprehensive Introduction

Understanding Python Terminology

Variables :

  1. A variable is a named reference to a value that is stored in memory.

  2. Variables are used to store data so that it can be used later in the program.

  3. Example : x=5 , age=35

Rules to Declare a variable :

➛ Variable names must start with a letter or underscore . Example - myVar, *name == valid 123name ,123_*name == invalid

➛Variable names are case-sensitive .

➛Variable names should be descriptive.

oooo➛Avoid using reserved words. ➛Use lowercase letters and underscores. ➛Avoid using single-character variable names.

Input/Output :

➛ Input ( ) Function :

~ It is used to read a line of text input from the user.

~ It takes an optional prompt string as an argument , which is displayed to the user before waiting for input.

~ Example : name=input(“ What’s your name ? “)

➛ Output ( ) Function :

~ It is used to outupt text to the console.

~ It can take one or more arguments ,which are separated by commas .

~ Example : print(“ Hello , World ! “) print(“The answer is : ,42)

~ We can also use special characters like \n (newline) and \t(tab) to format output.

Comments :

~ Comments are used to add explanatory text to your code that is not executed as part of the program.

~ It can help you and other developers to understand what your code does and why you made certain decisions. ~ It will not compile by compiler nd it doesn’t affect code

➛Single Line Comments :

~ lt start with # symbol and continue until the end of time.

~Example :

# This is a single line comment

x=6 #This is another single-line comment.

➛Multi-Line Comments :

~It is enclosed in triple quotes(“““) or single quotes(‘‘‘) and can span multiple lines.

~Example :

‘‘‘

This is a multi-line comment.

It can span multiple lines.

‘‘‘

x=5

Data Types :

~Dictionary Type ( Dict ) :

  • It represents a collection of key-value pairs .

  • Typically used to represent structured data like JSON or XML.

~ Numeric Type :

  • used to represent numbers , as int float and complex.

~ Boolean Type ( bool ) :

  • used to represent two values : True and False.

~ Set Type :

  • used to represents an unordered collection of unique items.

Debugging:

It is a process of identifying and fixing problems (also known as BUGS) in code.

'''Wite a program that asks user to enter a number
   Program should tell that number is odd or  even'''


num=input("Enter a number:")
num=int(num)

if num%2==0:
#reaminder
   print("number is even")
else:
   print("number is odd")

Operators in Python

Arithmetic Operator

3 + 5 = 8 Addition

7 - 3 = 4 Subtraction

7 * 3 = 21 Multiplication

8 / 4 = 2 Division

➛ 4=4 True

COMPARISON OPERATOR

➛4==4 True

➛ 3!=2 True Not Equal to

➛ 2>3 False

➛ 2<3 True Greater than

➛ 2>=2 True

➛ 3>=2 True Greater than or equal to

LOGICAL OPERATORS

➛ 3>2 and 4>1 True AND : Both condition must be true

➛ 3>2 and 4>5 False

➛ 3>2 or 4>5 True OR : one condition True

➛ 2>3 or 4>5 False