ITI (Trade - COPA) Day-23

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

  1. Low-Level Languages

    • Machine Language

    • Assembly Language

  2. 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

  1. Simple and Easy to Learn

  2. Interpreted Language

  3. High-Level Language

  4. Object-Oriented

  5. Portable

  6. Open Source

  7. Large Library Support

  8. Dynamic Typing

  9. Extensible

  10. Supports Multiple Programming Paradigms


4. Setting up Python and PATH

4.1 Installing Python

Steps:

  1. Download Python from official website

  2. Run installer

  3. Select “Add Python to PATH”

  4. Install

4.2 Setting PATH

PATH allows the system to recognize Python commands from any directory.

Check installation:

python --version

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:

if 10 > 5: print("10 is greater")

6. Comments in Python

Comments are used to explain code and are ignored by Python.

Types of Comments

  1. Single-line Comment

# This is a comment
  1. Multi-line Comment

""" This is a 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:

x = 10 name = "Python"

8. Data Types in Python

Python has several built-in data types.

8.1 Numeric Data Types

  • int (integer)

  • float (decimal)

  • complex

Example:

a = 10 b = 3.5

8.2 Text Data Type

  • str (string)

Example:

name = "ITI COPA"

8.3 Boolean Data Type

  • bool (True or False)

Example:

is_pass = True

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:

x = int(5.7) y = str(10)

10. Strings in Python

A string is a sequence of characters.

Creating Strings

s = "Python"

String Operations

  • Concatenation

  • Repetition

  • Indexing

  • Slicing

Example:

print(s[0]) print(s[0:3])

11. Boolean in Python

Boolean represents:

  • True

  • False

Used in conditions and comparisons.

Example:

a = 10 b = 5 print(a > b)

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

if a > b: print("A is greater")

13.2 if-else Statement

if a > b: print("A") else: print("B")

13.3 if-elif-else Statement

if x == 1: print("One") elif x == 2: print("Two") else: print("Other")

14. Looping in Python

Loops are used to repeat code.


14.1 while Loop

i = 1 while i <= 5: print(i) i += 1

14.2 for Loop

for i in range(5): print(i)

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:

mylist = [1, 2, 3, "Python"]

Operations:

  • append()

  • remove()

  • pop()

  • sort()


18. Tuple

A tuple is similar to list but immutable.

Example:

t = (1, 2, 3)

19. Sets

A set is an unordered collection of unique items.

Example:

s = {1, 2, 3}

20. Dictionaries

A dictionary stores data in key-value pairs.

Example:

student = {"name": "Ram", "age": 20}

21. Arrays

Arrays store elements of same data type.

Using array module:

import array a = array.array('i', [1,2,3])

22. Iterators

An iterator is an object that can be iterated.

Example:

mytuple = (1,2,3) for i in mytuple: print(i)

23. Modules in Python

A module is a file containing Python code.

Using a Module

import math print(math.sqrt(16))

24. Date and Time

Using datetime module:

import datetime print(datetime.datetime.now())

25. Math Module

Common functions:

  • sqrt()

  • pow()

  • ceil()

  • floor()


26. Input and Output

Input

name = input("Enter name: ")

Output

print(name)

MCQ QUESTIONS (50) – CBT EXAM

  1. Python is a ______ level language.
    A) Low
    B) Medium
    C) High
    D) Machine
    Ans: C

  2. Python was developed by:
    A) Dennis Ritchie
    B) James Gosling
    C) Guido van Rossum
    D) Bjarne Stroustrup
    Ans: C

  3. Python was released in:
    A) 1985
    B) 1991
    C) 2000
    D) 2010
    Ans: B

  4. Python is:
    A) Compiled
    B) Interpreted
    C) Assembled
    D) Machine
    Ans: B

  5. Which symbol is used for comments?
    A) //
    B) #
    C) /* */
    D) <!-- -->
    Ans: B

  6. Which is not a Python data type?
    A) int
    B) float
    C) char
    D) string
    Ans: C

  7. Python variables are:
    A) Fixed type
    B) Dynamic
    C) Static
    D) Constant
    Ans: B

  8. Which is correct Boolean value?
    A) true
    B) TRUE
    C) False
    D) false
    Ans: C

  9. Which operator is used for power?
    A) ^
    B) **
    C) //
    D) %
    Ans: B

  10. Which loop is entry-controlled?
    A) do-while
    B) for
    C) repeat
    D) switch
    Ans: B

  11. break statement is used to:
    A) Skip iteration
    B) Exit loop
    C) Continue loop
    D) Restart loop
    Ans: B

  12. continue statement is used to:
    A) Exit loop
    B) Skip iteration
    C) Stop program
    D) Break function
    Ans: B

  13. List is:
    A) Immutable
    B) Mutable
    C) Fixed
    D) Constant
    Ans: B

  14. Tuple is:
    A) Mutable
    B) Immutable
    C) Dynamic
    D) Editable
    Ans: B

  15. Set stores:
    A) Duplicate values
    B) Unique values
    C) Ordered values
    D) Indexed values
    Ans: B

  16. Dictionary stores data in:
    A) List
    B) Table
    C) Key-value pair
    D) Array
    Ans: C

  17. Which module is used for math operations?
    A) calc
    B) math
    C) number
    D) numeric
    Ans: B

  18. sqrt() function is in:
    A) array
    B) math
    C) datetime
    D) sys
    Ans: B

  19. Which function is used for input?
    A) read()
    B) scan()
    C) input()
    D) get()
    Ans: C

  20. Which function is used for output?
    A) echo()
    B) print()
    C) show()
    D) display()
    Ans: B

  21. range() is used in:
    A) while
    B) for
    C) if
    D) switch
    Ans: B

  22. Python uses indentation for:
    A) Comments
    B) Loop
    C) Block of code
    D) Variables
    Ans: C

  23. Which operator checks membership?
    A) is
    B) in
    C) ==
    D) not
    Ans: B

  24. Which is not a loop?
    A) for
    B) while
    C) repeat
    D) do
    Ans: C

  25. Arrays store elements of:
    A) Different types
    B) Same type
    C) Any type
    D) No type
    Ans: B

  26. Python is:
    A) Closed source
    B) Paid
    C) Open source
    D) Licensed
    Ans: C

  27. Which data type stores text?
    A) int
    B) float
    C) str
    D) bool
    Ans: C

  28. Which operator is logical AND?
    A) &
    B) and
    C) &&
    D) AND
    Ans: B

  29. Python supports:
    A) OOP only
    B) Procedural only
    C) Multiple paradigms
    D) None
    Ans: C

  30. Which module handles date and time?
    A) time
    B) calendar
    C) datetime
    D) clock
    Ans: C

  31. Python is used for:
    A) Web
    B) Data analysis
    C) AI
    D) All
    Ans: D

  32. Python file extension is:
    A) .pt
    B) .py
    C) .pyt
    D) .pn
    Ans: B

  33. Python variables are created when:
    A) Declared
    B) Assigned
    C) Defined
    D) Typed
    Ans: B

  34. Which keyword is used for conditions?
    A) when
    B) if
    C) check
    D) case
    Ans: B

  35. elif is used when:
    A) Multiple conditions
    B) Looping
    C) Input
    D) Output
    Ans: A

  36. pass statement does:
    A) Stops program
    B) Skips loop
    C) Does nothing
    D) Ends function
    Ans: C

  37. Which is mutable?
    A) tuple
    B) string
    C) list
    D) int
    Ans: C

  38. pop() is used in:
    A) tuple
    B) set
    C) list
    D) string
    Ans: C

  39. Dictionary keys must be:
    A) Mutable
    B) Immutable
    C) List
    D) Set
    Ans: B

  40. Iteration means:
    A) Execution
    B) Looping
    C) Condition
    D) Input
    Ans: B

  41. Module is:
    A) Variable
    B) File
    C) Class
    D) Loop
    Ans: B

  42. import keyword is used for:
    A) Output
    B) Module
    C) Loop
    D) Input
    Ans: B

  43. Which operator is floor division?
    A) /
    B) %
    C) //
    D) **
    Ans: C

  44. Python code is executed:
    A) Line by line
    B) Block by block
    C) At once
    D) Randomly
    Ans: A

  45. Which is correct list?
    A) {1,2,3}
    B) (1,2,3)
    C) [1,2,3]
    D) <1,2,3>
    Ans: C

  46. Which is a set?
    A) [1,2]
    B) (1,2)
    C) {1,2}
    D) <1,2>
    Ans: C

  47. Python supports automation because it is:
    A) Fast
    B) Simple
    C) Powerful
    D) All
    Ans: D

  48. Which function returns length?
    A) size()
    B) count()
    C) len()
    D) total()
    Ans: C

  49. Python is best for beginners because:
    A) Complex syntax
    B) Simple syntax
    C) Slow
    D) Old
    Ans: B

  50. 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

ITI (Trade - COPA) Day-23

ITI COPA (Computer Operator & Programming Assistant) – Basic Notes TOPIC- PROGRAMMING LANGUAGE – PYTHON 1. Introduction to Programming...