| Table of contents | |
| Applications of | |
| Installation of | |
| Python Statements and Comments | |
| Python Keywords and Identifiers | |
| Variables, Constants and Data Types | |
| Operators | |
| Type Conversion | |
| Python Input and Output |
At the core of many modern artificial intelligence systems is Python. It is the language commonly used by data scientists and engineers to build AI systems and the supporting infrastructure. Several other languages - such as Lisp, Prolog, C++, and Java - can be used to create AI applications, but Python is the most popular for the following reasons.
Python is a high-level, general-purpose programming language used widely across domains. It can be used to write virtually any program describable in code. Common application areas include:
After installing Python you will normally use an development environment to write programs. IDLE (Integrated Development and Learning Environment) is the basic editor and shell that comes bundled with the standard Python distribution.
IDLE has two main modes:
A statement is a piece of code that can be executed by the Python interpreter. Anything that performs an action in Python is a statement. Examples include assignment statements, conditional statements, loop statements and function calls. The end of a statement is usually indicated by a newline.
Multiline statements
If a statement is too long for one physical line, you can extend it to multiple lines using the line continuation character \\ or by using grouping constructs such as parentheses (...), brackets [...] or braces {...}. This is useful for long calculations or long data structures so the code remains readable.

Comments are lines of text in source code that are ignored by the interpreter. They explain code, improve readability and help others (or your future self) understand why code was written in a certain way. There are two common styles of comments in Python.
# Single line comment
# Multiple line comment 1 # Multiple line comment 2
"""This is a multiline comment or documentation string. It can span several lines."""
Keywords are reserved words in Python used by the interpreter to recognise the program’s structure. Keywords have fixed meanings and cannot be used as variable names, function names or identifiers. Most keywords are lowercase; booleans are True and False.
Examples of keywords include: False, class, finally, is, return, None, continue, for, lambda, try, True, def, from, nonlocal, while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import, pass, break, except, in, raise.
Identifiers are names given to variables, functions, classes, modules, or other objects. Rules for identifiers:
Examples of valid identifiers:
A variable is a named memory location used to store a value. In Python, a variable is created when a value is first assigned to it. Declaration is implicit; you do not need a separate declaration statement.
Rules for variable names follow the identifier rules: start with a letter or underscore, no special characters, case-sensitive.
Constants are variables whose values should not be changed during program execution. Python has no built-in constant type, but by convention constants are written in uppercase. Example:
NAME = "Rajesh Kumar" AGE = 20
Every value in Python has a data type. Data types describe what kind of value an object holds. Important categories include Numbers, Sequences, Sets, and Mappings.
Number data types store numeric values. Four common numeric categories in Python:
x = 500
x = 50.5
x = 10 + 4j
x = 15 > 6 type(x)
A sequence is an ordered, indexed collection. Python provides both mutable and immutable sequence types.
name = "Rakesh kumar"
dob = [19, "January", 1995]
newtuple = (15, 20, 20, 40, 60, 70)
A set is an unordered collection without duplicate elements. Sets have no index and are declared using curly brackets. Example:
newset = {10, 20, 30}
Dictionaries are unordered collections of key–value pairs. Keys are used to access values. Dictionaries are declared with curly brackets and a colon separates keys and values:
d = {1: 'Ajay', 'key': 2}
Operators perform operations on operands (values or variables). The same operator can behave differently for different data types. Categories of operators include:
Used for mathematical operations such as addition, subtraction, multiplication and division. Examples include +, -, *, /, //, %, .

Used when assigning values to variables. The basic operator is =, and there are compound assignment operators such as +=, -=, *=, etc.

Comparison operators (also called relational operators) compare values and return True or False. Examples: ==, !=, >, <, >=, <=.

Logical operators combine multiple boolean expressions. Common logical operators are and, or, not.

Type conversion is the process of converting a value from one data type to another. There are two kinds:
When combining an integer and a float, Python promotes the integer to float automatically:
x = 5 y = 2.5 z = x / y # z will be a float after execution
You can convert a value’s type intentionally using conversion functions:
Birth_day = 21 Birth_day = str(Birth_day)
Use print() to display output on the screen (standard output). Example:
a = "Hello World!" print(a)
Output: Hello World!
Use input() to receive input from the user. The function returns a string; convert as needed. Example:
name = input("Enter your name: ") age = int(input("Enter your age: "))
24 videos|67 docs|8 tests |
| 1. Why is Python considered a popular choice for AI development? | ![]() |
| 2. How can I install Python on my computer? | ![]() |
| 3. What are Python keywords and why are they important? | ![]() |
| 4. What are the basic data types available in Python? | ![]() |
| 5. How do I take user input in Python? | ![]() |