ITI COPA (Computer Operator & Programming Assistant) – Basic Notes
TOPIC- PROGRAMMING LANGUAGE – PYTHON
1. Introduction to Programming Languages
A programming language is a formal language used to give instructions to a computer so that it can perform specific tasks. Programming languages help humans communicate with computers.
Types of Programming Languages
-
Low-Level Languages
-
Machine Language
-
Assembly Language
-
-
High-Level Languages
-
C, C++, Java, Python, JavaScript
-
Python is a high-level, interpreted, and general-purpose programming language.
2. Introduction to Python
2.1 What is Python?
Python is a popular, easy-to-learn, high-level programming language used for:
-
Software development
-
Web development
-
Data analysis
-
Artificial Intelligence
-
Automation
-
Machine learning
Python focuses on readability and simplicity, making it ideal for beginners.
2.2 History of Python
-
Python was created by Guido van Rossum
-
First released in 1991
-
Named after the TV show “Monty Python’s Flying Circus”
-
Developed at CWI (Centrum Wiskunde & Informatica), Netherlands
Major Python Versions
-
Python 1.x – Early version
-
Python 2.x – Improved version (now discontinued)
-
Python 3.x – Latest and widely used version
2.3 Why Python is Popular
-
Simple syntax
-
Easy to learn
-
Large standard library
-
Open source
-
Platform independent
3. Features of Python
-
Simple and Easy to Learn
-
Interpreted Language
-
High-Level Language
-
Object-Oriented
-
Portable
-
Open Source
-
Large Library Support
-
Dynamic Typing
-
Extensible
-
Supports Multiple Programming Paradigms
4. Setting up Python and PATH
4.1 Installing Python
Steps:
-
Download Python from official website
-
Run installer
-
Select “Add Python to PATH”
-
Install
4.2 Setting PATH
PATH allows the system to recognize Python commands from any directory.
Check installation:
5. Python Basic Syntax
5.1 Python Syntax Rules
-
Python uses indentation instead of braces
-
Code blocks are defined by indentation
-
Statements end without semicolons
Example:
6. Comments in Python
Comments are used to explain code and are ignored by Python.
Types of Comments
-
Single-line Comment
-
Multi-line Comment
7. Variables in Python
A variable is a container used to store data.
Rules for Variable Naming
-
Must start with a letter or underscore
-
Cannot start with a number
-
Case-sensitive
-
No special symbols
Example:
8. Data Types in Python
Python has several built-in data types.
8.1 Numeric Data Types
-
int (integer)
-
float (decimal)
-
complex
Example:
8.2 Text Data Type
-
str (string)
Example:
8.3 Boolean Data Type
-
bool (True or False)
Example:
8.4 Sequence Data Types
-
list
-
tuple
-
range
8.5 Set Data Type
-
set
8.6 Mapping Data Type
-
dictionary
9. Type Casting in Python
Type casting means converting one data type into another.
Types of Casting
-
int()
-
float()
-
str()
Example:
10. Strings in Python
A string is a sequence of characters.
Creating Strings
String Operations
-
Concatenation
-
Repetition
-
Indexing
-
Slicing
Example:
11. Boolean in Python
Boolean represents:
-
True
-
False
Used in conditions and comparisons.
Example:
12. Python Operators
12.1 Arithmetic Operators
-
+, -, *, /, %, **, //
12.2 Comparison Operators
-
==, !=, >, <, >=, <=
12.3 Logical Operators
-
and, or, not
12.4 Assignment Operators
-
=, +=, -=
12.5 Membership Operators
-
in, not in
12.6 Identity Operators
-
is, is not
13. Conditional Statements
Used to make decisions.
13.1 if Statement
13.2 if-else Statement
13.3 if-elif-else Statement
14. Looping in Python
Loops are used to repeat code.
14.1 while Loop
14.2 for Loop
15. Control Statements
-
break
-
continue
-
pass
16. String Manipulation
Common string methods:
-
upper()
-
lower()
-
replace()
-
split()
-
find()
17. Lists
A list is a collection of items.
Example:
Operations:
-
append()
-
remove()
-
pop()
-
sort()
18. Tuple
A tuple is similar to list but immutable.
Example:
19. Sets
A set is an unordered collection of unique items.
Example:
20. Dictionaries
A dictionary stores data in key-value pairs.
Example:
21. Arrays
Arrays store elements of same data type.
Using array module:
22. Iterators
An iterator is an object that can be iterated.
Example:
23. Modules in Python
A module is a file containing Python code.
Using a Module
24. Date and Time
Using datetime module:
25. Math Module
Common functions:
-
sqrt()
-
pow()
-
ceil()
-
floor()
26. Input and Output
Input
Output
MCQ QUESTIONS (50) – CBT EXAM
-
Python is a ______ level language.
A) Low
B) Medium
C) High
D) Machine
Ans: C -
Python was developed by:
A) Dennis Ritchie
B) James Gosling
C) Guido van Rossum
D) Bjarne Stroustrup
Ans: C -
Python was released in:
A) 1985
B) 1991
C) 2000
D) 2010
Ans: B -
Python is:
A) Compiled
B) Interpreted
C) Assembled
D) Machine
Ans: B -
Which symbol is used for comments?
A) //
B) #
C) /* */
D) <!-- -->
Ans: B -
Which is not a Python data type?
A) int
B) float
C) char
D) string
Ans: C -
Python variables are:
A) Fixed type
B) Dynamic
C) Static
D) Constant
Ans: B -
Which is correct Boolean value?
A) true
B) TRUE
C) False
D) false
Ans: C -
Which operator is used for power?
A) ^
B) **
C) //
D) %
Ans: B -
Which loop is entry-controlled?
A) do-while
B) for
C) repeat
D) switch
Ans: B -
break statement is used to:
A) Skip iteration
B) Exit loop
C) Continue loop
D) Restart loop
Ans: B -
continue statement is used to:
A) Exit loop
B) Skip iteration
C) Stop program
D) Break function
Ans: B -
List is:
A) Immutable
B) Mutable
C) Fixed
D) Constant
Ans: B -
Tuple is:
A) Mutable
B) Immutable
C) Dynamic
D) Editable
Ans: B -
Set stores:
A) Duplicate values
B) Unique values
C) Ordered values
D) Indexed values
Ans: B -
Dictionary stores data in:
A) List
B) Table
C) Key-value pair
D) Array
Ans: C -
Which module is used for math operations?
A) calc
B) math
C) number
D) numeric
Ans: B -
sqrt() function is in:
A) array
B) math
C) datetime
D) sys
Ans: B -
Which function is used for input?
A) read()
B) scan()
C) input()
D) get()
Ans: C -
Which function is used for output?
A) echo()
B) print()
C) show()
D) display()
Ans: B -
range() is used in:
A) while
B) for
C) if
D) switch
Ans: B -
Python uses indentation for:
A) Comments
B) Loop
C) Block of code
D) Variables
Ans: C -
Which operator checks membership?
A) is
B) in
C) ==
D) not
Ans: B -
Which is not a loop?
A) for
B) while
C) repeat
D) do
Ans: C -
Arrays store elements of:
A) Different types
B) Same type
C) Any type
D) No type
Ans: B -
Python is:
A) Closed source
B) Paid
C) Open source
D) Licensed
Ans: C -
Which data type stores text?
A) int
B) float
C) str
D) bool
Ans: C -
Which operator is logical AND?
A) &
B) and
C) &&
D) AND
Ans: B -
Python supports:
A) OOP only
B) Procedural only
C) Multiple paradigms
D) None
Ans: C -
Which module handles date and time?
A) time
B) calendar
C) datetime
D) clock
Ans: C -
Python is used for:
A) Web
B) Data analysis
C) AI
D) All
Ans: D -
Python file extension is:
A) .pt
B) .py
C) .pyt
D) .pn
Ans: B -
Python variables are created when:
A) Declared
B) Assigned
C) Defined
D) Typed
Ans: B -
Which keyword is used for conditions?
A) when
B) if
C) check
D) case
Ans: B -
elif is used when:
A) Multiple conditions
B) Looping
C) Input
D) Output
Ans: A -
pass statement does:
A) Stops program
B) Skips loop
C) Does nothing
D) Ends function
Ans: C -
Which is mutable?
A) tuple
B) string
C) list
D) int
Ans: C -
pop() is used in:
A) tuple
B) set
C) list
D) string
Ans: C -
Dictionary keys must be:
A) Mutable
B) Immutable
C) List
D) Set
Ans: B -
Iteration means:
A) Execution
B) Looping
C) Condition
D) Input
Ans: B -
Module is:
A) Variable
B) File
C) Class
D) Loop
Ans: B -
import keyword is used for:
A) Output
B) Module
C) Loop
D) Input
Ans: B -
Which operator is floor division?
A) /
B) %
C) //
D) **
Ans: C -
Python code is executed:
A) Line by line
B) Block by block
C) At once
D) Randomly
Ans: A -
Which is correct list?
A) {1,2,3}
B) (1,2,3)
C) [1,2,3]
D) <1,2,3>
Ans: C -
Which is a set?
A) [1,2]
B) (1,2)
C) {1,2}
D) <1,2>
Ans: C -
Python supports automation because it is:
A) Fast
B) Simple
C) Powerful
D) All
Ans: D -
Which function returns length?
A) size()
B) count()
C) len()
D) total()
Ans: C -
Python is best for beginners because:
A) Complex syntax
B) Simple syntax
C) Slow
D) Old
Ans: B -
Python is widely used in:
A) AI
B) ML
C) Data Science
D) All
Ans: D
No comments:
Post a Comment
Give your valuable feedback