0% found this document useful (0 votes)
7 views3 pages

Python Unit 1 Exam Notes Summary

The document provides comprehensive notes on Python, covering its origin, key features, basic program structure, identifiers, reserved words, escape sequences, and the IDLE environment. It also discusses operators, variables, control flow statements, mutable vs immutable types, list operations, and methods, as well as examples of sets, tuples, and dictionaries. Overall, it serves as a foundational guide for understanding Python programming concepts and syntax.

Uploaded by

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

Python Unit 1 Exam Notes Summary

The document provides comprehensive notes on Python, covering its origin, key features, basic program structure, identifiers, reserved words, escape sequences, and the IDLE environment. It also discusses operators, variables, control flow statements, mutable vs immutable types, list operations, and methods, as well as examples of sets, tuples, and dictionaries. Overall, it serves as a foundational guide for understanding Python programming concepts and syntax.

Uploaded by

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

Python – Unit 1: Exam Notes

Q1. Origin and Need for Python


- Origin: Python was developed by Guido van Rossum in 1980s, released in 1991 at CWI.
- Need: Easy to read, high productivity, portable, large library, supports AI, ML, data science.

Q2. Five Key Features of Python


1. Simple & Readable
2. Interpreted
3. Dynamic Typing
4. Portable
5. Extensive Libraries

Q3. Basic Structure of a Python Program


Example:
def main():
print("Hello World")
a, b = 5, 10
print("Sum:", a + b)
if __name__ == "__main__":
main()

Q4. Identifiers in Python


- Names for variables, functions, classes.
Rules: Start with letter/underscore, no digits first, case-sensitive, no keywords.

Q5. Reserved Words (any 10)


Examples: if, else, elif, while, for, break, continue, class, def, return

Q6. Escape Sequences


Examples:
print("Hello\nWorld") → Newline
print("Hello\tWorld") → Tab
print("He said \"Hi\"") → Double quote

Q7. IDLE in Python


- IDLE = Integrated Development and Learning Environment
- Modes: Interactive Mode (Shell), Script Mode (.py file)

Q8. Operators
- Relational: 5 > 3 → True
- Logical: True or False → True
- Bitwise: 5 & 3 → 1
Q9. Variables & Assignment
Example: name = "Harjot"; age = 19

Q10. If-Elif-Else with Nested


marks = 85
if marks >= 90: print("Grade A")
elif marks >= 75:
if marks >= 80: print("Grade B+")
else: print("Grade B")
else: print("Grade C")

Q11. Mutable vs Immutable


- Mutable: List, Dict, Set (can change)
- Immutable: String, Tuple, Numbers (cannot change)

Q12. List Slicing


numbers = [10,20,30,40,50]
print(numbers[1:4]) → [20,30,40]

Q13. List Traversal


for f in ["apple","banana","cherry"]: print(f)

Q14. List Operations


a=[1,2]; b=[3,4]
a+b → [1,2,3,4]
a*2 → [1,2,1,2]
2 in a → True

Q15. List Methods (append, extend, insert)


lst=[1,2]
[Link](3) → [1,2,3]
[Link]([4,5]) → [1,2,3,4,5]
[Link](1,10) → [1,10,2,3,4,5]

Q16. List Methods (pop, remove, index, sort)


lst=[5,3,8,1,3]
[Link]() → removes last
[Link](3) → removes first 3
[Link](8) → 1
[Link]() → [1,3,5,8]

Q17. Set Example


s={1,2,3,2}
print(s) → {1,2,3}

Q18. Tuple Example


t=(10,20,30)
t[1] → 20
t+t → (10,20,30,10,20,30)

Q19. Dictionary Example


student={"name":"Harjot","age":19}
student["age"]=20
del student["name"]

Q20. Dictionary Methods


get(): [Link]("age") → 19
update(): [Link]({"course":"CS"})
copy(): new = [Link]()

Common questions

Powered by AI

Python's set data structure inherently handles duplicates by maintaining only unique elements. When a list with duplicates is converted to a set, the duplicates are automatically removed, assisting in tasks such as identifying unique items or preparing data for operations that require non-redundant elements .

String immutability in Python means once a string is created, it cannot be changed. This feature ensures safe and efficient memory usage as strings don't change state unexpectedly, which is crucial in multi-threaded environments. For example, concatenating strings often generates a new string rather than modifying the existing one, which can impact performance negatively if done excessively .

Python's dynamic typing feature allows variables to change types, which enhances flexibility and ease of use. This reduces the need for explicit type declarations and enables quicker development cycles, as developers do not need to manage types directly .

Python was developed by Guido van Rossum in the 1980s and released in 1991 at CWI to address the need for a programming language that is easy to read and has high productivity. It is also portable, has a large library, and supports areas like artificial intelligence, machine learning, and data science, making it widely adopted in the tech community .

Python's reserved words, such as 'if', 'else', 'while', etc., impose structured patterns on the code, ensuring clarity and integrity. They serve as fundamental building blocks for syntax, which helps maintain a consistent code base that is both readable and reliable, as they restrict the use of these words as identifiers .

Python's list slicing allows users to easily access parts of a list without modifying the original data. This capability facilitates efficient data manipulation, enabling users to extract, rearrange, or process subsets of data seamlessly, as seen in slicing operations like numbers[1:4] which outputs a new list with selected elements .

Python's extensive libraries, such as NumPy, Pandas, TensorFlow, and Scikit-learn, provide powerful tools for data manipulation, analysis, and machine learning. These libraries simplify complex tasks, accelerate development processes, and allow Python to be a preferred language in data-intensive disciplines like data science and machine learning .

Python's IDLE serves as an Integrated Development and Learning Environment, providing an accessible way for newcomers to interactively and script their programs. It simplifies the coding learning curve by offering a straightforward user interface to execute commands and view outputs immediately, thereby making Python more approachable as a first programming language .

Python being an interpreted language allows for the execution of code one line at a time, which facilitates easier debugging and testing. It helps developers find and fix errors while the program runs, promoting a fast development process. However, the interpreted nature might contribute to slower performance compared to compiled languages .

Logical operators such as 'and', 'or', and 'not' are crucial for decision-making in Python programs. They allow the combination of multiple boolean expressions to control the flow of execution based on conditional logic. Their correct use helps in forming complex conditions that determine the behavior of program elements effectively .

You might also like