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

02 Practical Python Basics

This document serves as a beginner's guide to Python programming, covering its uses, core vocabulary, and fundamental concepts such as variables, conditions, loops, and functions. It includes practical advice on naming conventions, debugging techniques, and mini exercises for hands-on practice. The content is designed to help new programmers understand the basics of Python in a clear and accessible manner.

Uploaded by

ranjithkumarsv75
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 views2 pages

02 Practical Python Basics

This document serves as a beginner's guide to Python programming, covering its uses, core vocabulary, and fundamental concepts such as variables, conditions, loops, and functions. It includes practical advice on naming conventions, debugging techniques, and mini exercises for hands-on practice. The content is designed to help new programmers understand the basics of Python in a clear and accessible manner.

Uploaded by

ranjithkumarsv75
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

Practical Python Basics

Beginner programming notes with examples and exercises

Original educational document. Created as general study material; edit freely before use.

1. What Python Is Used For


Python is a readable programming language used for automation, web development, data analysis, scripting,
artificial intelligence experiments, and general problem solving. Beginners often start with Python because the
syntax is close to plain English and the standard library includes many useful tools.

2. Core Vocabulary
Term Meaning Tiny example
Variable A name that stores a value score = 85
String Text data name = "Anu"
Integer Whole number age = 19
Float Decimal number price = 49.5
Boolean True or False value is_ready = True
Function Reusable block of code def greet(): ...

3. Variables and Types


A variable should have a meaningful name. Prefer names like total_marks or file_path instead of x when the
purpose is not obvious. Python decides the type of a value at runtime, so a variable can hold different kinds of data,
but changing types often can make code confusing.

 Use lowercase words separated by underscores for readable variable names.


 Keep one clear purpose per variable.
 Convert input text to numbers before doing arithmetic.
 Print intermediate values when debugging a beginner program.

4. Conditions
Conditions let a program choose different actions. The most common structure uses if, elif, and else. Indentation is
part of Python syntax; the lines inside a condition must be consistently indented.

Need Structure Example idea


One condition if If marks are above 50, pass
If logged in, show dashboard; otherwise
Two choices if / else
show login
Many choices if / elif / else Grade A, B, C, or retry

5. Loops
A loop repeats work. Use a for loop when you know the collection or range you want to process. Use a while loop
when repetition depends on a changing condition. Always check that a while loop can actually stop.

Loop Best use Risk to avoid


for Reading items in a list Using unclear loop variable names
Original study notes | Prepared for personal learning use
while Repeating until a condition changes Infinite loop

6. Functions
A function turns repeated logic into a reusable named action. A good function does one clear job, has a short name
that explains its purpose, and returns a value when the caller needs a result.

 Bad name: do_it(). Better name: calculate_average().


 Keep functions short enough to understand at a glance.
 Use parameters for values that change from call to call.
 Return data instead of printing when another part of the program needs the answer.

7. Debugging Checklist
1. Read the error message from bottom to top and identify the line number.
2. Check spelling, capitalization, and indentation.
3. Print variable values before the failing line.
4. Test with a very small input before trying a large input.
5. Explain the code aloud; unclear explanations often reveal the mistake.

8. Mini Exercises
6. Write a program that asks for two numbers and prints their sum.
7. Create a list of five subjects and print each subject on a new line.
8. Write a function that converts minutes into hours and remaining minutes.
9. Write a condition that prints Pass when marks are at least 50.
10. Create a loop that counts from 10 down to 1.

Original study notes | Prepared for personal learning use

You might also like