0% found this document useful (0 votes)
4 views2 pages

Python Tokens

The document provides an overview of Python programming, covering its basic concepts such as tokens, variables, data types, input/output functions, type conversion, operators, and conditional statements. It emphasizes Python's simplicity and readability, making it accessible for beginners. Additionally, it highlights the importance of proper indentation for code execution.

Uploaded by

amreenzaria1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Python Tokens

The document provides an overview of Python programming, covering its basic concepts such as tokens, variables, data types, input/output functions, type conversion, operators, and conditional statements. It emphasizes Python's simplicity and readability, making it accessible for beginners. Additionally, it highlights the importance of proper indentation for code execution.

Uploaded by

amreenzaria1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Basics of Python and Decision Making

1. Introduction to Python
Python is a high-level programming language that is simple and easy to understand. It is an
interpreted language, which means the code is executed line by line. Python is widely used because
its syntax is similar to English, making it easy for beginners.

2. Tokens in Python
Tokens are the smallest units of a Python program.
Keywords are reserved words that have a fixed meaning in Python. They cannot be used as
variable names. Examples are if, else, elif, True, and False.
Identifiers are the names given to variables, functions, or other objects. An identifier must start with
a letter or underscore and cannot be a keyword.
Literals are fixed values used in a program. Examples are numbers like 10, 3.5, and strings like
"hello".
Operators are symbols used to perform operations on variables and values.

3. Variables and Data Types


A variable is used to store data in a program. The value of a variable can change during execution.
An integer (int) is used to store whole numbers.
A float (float) is used to store decimal numbers.
A string (str) is used to store text enclosed in quotes.
A boolean (bool) stores either True or False.

4. Input and Output


The input() function is used to take input from the user. The print() function is used to display output
on the screen.
Example:
name = input("Enter your name: ")
print("Hello", name)

5. Type Conversion
Type conversion is used to change one data type into another.
The int() function converts a value to an integer.
The float() function converts a value to a decimal number.
The str() function converts a value to a string.
Example:
num = int(input("Enter a number: "))

6. Operators in Python
Arithmetic operators are used to perform mathematical calculations. Examples include addition (+),
subtraction (-), multiplication (*), division (/), modulus (%), floor division (//), and exponent (**).
Relational operators are used to compare two values. The result is always True or False. Examples
include greater than (>), less than (<), equal to (==), not equal to (!=), greater than or equal to (>=),
and less than or equal to (<=).
Logical operators are used to combine conditions. The and operator returns True if both conditions
are true. The or operator returns True if at least one condition is true. The not operator reverses the
result.

7. Conditional Statements
Conditional statements are used to make decisions in a program.
The if statement is used to execute a block of code only when a condition is true.
Syntax:
if condition:
statement
Example:
x=5
if x > 0:
print("Positive number")
The if-else statement is used when there are two possible outcomes.
Syntax:
if condition:
statement1
else:
statement2
Example:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
The if-elif-else statement is used when there are multiple conditions.
Syntax:
if condition1:
statement1
elif condition2:
statement2
else:
statement3
Example:
marks = int(input("Enter marks: "))
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
else:
print("Grade C")

8. Indentation in Python
Indentation refers to the spaces given before a statement. It is used to define a block of code in
Python. Proper indentation is necessary, otherwise the program will give an error.

Final Revision
Python is a simple and interpreted language.
Tokens include keywords, identifiers, literals, and operators.
Variables store data of different types such as int, float, string, and boolean.
Input and output are done using input() and print().
Operators are used for calculations and comparisons.
Conditional statements such as if, if-else, and if-elif-else are used for decision making.

You might also like