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

Chapter-1 Python Variables Zero To Hero

Chapter 1 introduces variables in Python, explaining their purpose, naming rules, and data types. It covers concepts such as dynamic typing, type conversion, and common mistakes, while emphasizing the importance of variables in GenAI applications. A mini project on student registration reinforces the practical application of these concepts.

Uploaded by

kantemahendra
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)
3 views3 pages

Chapter-1 Python Variables Zero To Hero

Chapter 1 introduces variables in Python, explaining their purpose, naming rules, and data types. It covers concepts such as dynamic typing, type conversion, and common mistakes, while emphasizing the importance of variables in GenAI applications. A mini project on student registration reinforces the practical application of these concepts.

Uploaded by

kantemahendra
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

Python for GenAI Engineers (Zero to Hero)

Chapter 1: Variables
Purpose
This chapter builds the foundation for Python and GenAI.

1. What is a Variable?
A variable is a named memory location used to store data.
Example:
name='Anitha'
age=25

2. Why Variables?
Variables make programs readable and reusable. Instead of remembering values, we
remember meaningful names.

3. Assignment Operator (=)


= assigns the value on the right to the variable on the left.
Example:
salary=50000

4. Memory (RAM)
When a program runs, variable values are stored in RAM temporarily. When the program
ends, RAM is cleared.

5. Naming Rules
• Start with a letter or _
• No spaces
• No hyphen
• Don't use Python keywords
• Use meaningful names like employee_salary.

6. Data Types
str: Text
int: Whole numbers
float: Decimal numbers
bool: True/False
Examples:
name='Anitha'
age=25
height=5.8
is_student=True

7. Dynamic Typing
Python automatically detects data types.
Example:
x=10
x='Python'

8. type()
Use type(variable) to check the datatype.
Example:
print(type(age))

9. print()
Displays output on the screen.
Example:
print(name)

10. input()
Takes input from the user. input() always returns a string.

11. Type Conversion


Convert data types using int(), float(), str(), bool().
Example:
age=int(input('Age: '))

12. Multiple Assignment


name, age='Anitha',25
x=y=z=100

13. Swapping
a,b=10,20
a,b=b,a

14. Real-time GenAI Connection


Variables are used to store prompts, model names, temperatures, token limits, embeddings,
tool outputs, user queries and responses.

15. Common Mistakes


Missing quotes around strings, invalid variable names, forgetting input() returns string.
16. Interview Questions
What is a variable?
What is dynamic typing?
Why does input() return string?
Difference between variable and value?
What is type conversion?

17. Mini Project


Student Registration:
Take name, age, city and marks using input(). Convert age and marks to correct types and
print the profile.

Chapter Summary
Variables are the foundation of Python. Learn to store data, choose correct data types, use
print() and input(), convert types properly, and write meaningful variable names. These
concepts are used throughout GenAI, from prompts to RAG and AI agents.

You might also like