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

Python Basics Formatted Notes

The document provides an overview of Python basics, including creating code, using functions, variables, and data types such as strings, integers, and floats. It emphasizes the importance of readability through comments and pseudocode, as well as the use of formatted strings and function definitions. Code examples illustrate user input handling, function creation, and returning values.

Uploaded by

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

Python Basics Formatted Notes

The document provides an overview of Python basics, including creating code, using functions, variables, and data types such as strings, integers, and floats. It emphasizes the importance of readability through comments and pseudocode, as well as the use of formatted strings and function definitions. Code examples illustrate user input handling, function creation, and returning values.

Uploaded by

jasirahamed345
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 Basics – Clean Notes

Creating Code with Python


VS Code is a text editor that allows you to browse files, edit code, and run commands using a
terminal. You can create a Python file such as [Link] and write your first program.

Your First Program


Example:
print("hello, world")

Functions
Functions are actions that Python already knows how to perform. The print() function outputs text
to the terminal.

Variables
Variables act as containers for storing values. They allow your program to remember user input or
calculations.

Example with Input


name = input("What's your name? ")
print(f"hello, {name}")

Comments and Pseudocode


Comments help explain what your code does. Pseudocode is a planning-style comment used to
think through logic.

Strings and Formatting


Strings are text values. Formatted strings (f-strings) are the cleanest way to combine text and
variables.

Integers and Casting


Input is read as text (string). Casting converts it into an integer using int().

Floats and Rounding


Floats are numbers with decimals. You can round values using round() or format output using
f-strings.

Defining Functions
Functions are created using the def keyword. They help reuse logic and keep code readable.
Returning Values
Functions can return values using the return keyword. Returned values can be reused elsewhere
in the program.

Summary
You learned Python basics including variables, functions, strings, integers, floats, readability
principles, and returning values.

Code Examples
# Ask the user for their name
name = input("What's your name? ").strip().title()
print(f"hello, {name}")

x = int(input("What's x? "))
y = int(input("What's y? "))
print(x + y)

def hello(to="world"):
print("hello,", to)

name = input("What's your name? ")


hello(name)
hello()

def main():
x = int(input("What's x? "))
print("x squared is", square(x))

def square(n):
return n * n

main()

You might also like