start-coding-with
PYTHON
PYTHON
Where do I start?
Whether you're a tech enthusiast, a career changer, or someone simply curious about the art of programming, taking your first steps can be both thrilling and a little overwhelming. In this blog post, we'll guide you through the basics of starting your coding journey with Python, a versatile and beginner-friendly programming language.
Setting up the environment
Let's go easy and simple...
Before we start coding, we need to set up our coding environment. Installing Python on a computer is the first step. Additionally, choosing an Integrated Development Environment (IDE) is crucial for a seamless coding experience. IDEs like VSCode or PyCharm provide tools to write, test, and debug your code efficiently.
Setting up your coding environment is like decorating a room – install Python as the foundation, choose an IDE for comfort and efficiency, and create a space where your coding ideas can come to life.
Get compatible python from python.org
Install Python: A step-by-step guide to downloading and installing Python on your computer.
(Note to click on [] Add python to path 👉
Choosing an IDE (Integrated Development Environment): Explore beginner-friendly IDEs like VSCode, PyCharm, or Jupyter for a smooth coding experience.
Once you have successfully installed python you can type command "python --version" on your command line or terminal depending upon your OS. It should show which version of python installed.
And if the python is linked on the path then typing python on the command line would start the python shell or interpreter as we can start typing and run code line by line.
Your first hello world
python on file...
python ./filename.py
Datatypes
Like Real numbers, Whole numbers, Integers , Decimal Numbers, Rational and irrational numbers in maths.
my_integer = 42
my_float = 3.14
my_string = "Hello, Python!"
is_true = True
is_false = False
my_list = [1, 2, 3, 4, 5]
my_tuple = (10, 20, 30)
my_set = {1, 2, 3, 4, 5}
my_dict = {'name': 'John', 'age': 25, 'city': 'New York'}
no_value = None
Variables
In coding, think of variables as labeled boxes where you keep different types of information. Just like you sort your toys into different boxes, learning about data types in Python (like numbers, words, and true/false values) helps you organize and work with your information in a super smart way. It's like learning the ABCs before writing stories – the basics that set you up for cooler, more complex stuff in the coding world!
# Good variable names
total_count = 100
user_name = "JohnDoe"
# Avoid using reserved words
# class = "Python" # This will raise an error
# Dynamic typing
x = 10
x = "Hello"
Operators in python
x = 5
y = 2
sum_result = x + y
difference_result = x - y
product_result = x * y
division_result = x / y
x = 5
y = 2
x += y # Equivalent to x = x + y
x = 5
y = 2
is_equal = x == y
is_greater = x > y
x = True
y = False
logical_and = x and y
logical_or = x or y
logical_not = not x
x = 5
y = 2
sum_result = x + y
difference_result = x - y
product_result = x * y
division_result = x / y
x = 5
y = 2
x += y # Equivalent to x = x + y
Control Flow: Making Decisions and Repeating Actions
Control flow, like using if statements for decisions and loops for repetition, guides your program's flow. There are two main types:
today = "Saturday"
print("Today is", today)
def say_hello():
print('Hello there!')
print('How are you?')
say_hello()
A parameter is a variable that is used in the function definition.
It's a placeholder for the actual value that will be passed to the defined function.
Parameters are placed in the function's signature and act as input placeholders.
An argument is a value that is passed to a function when invoking or calling it.
It is the actual value that is supplied to the function during the function call.
Arguments are provided in the function call and they get assigned to the corresponding parameters.
def filter_even(number_list): # 'number_list' is a parameter
result_list = []
for number in number_list:
if number % 2 == 0:
result_list.append(number)
return result_list
even_list = filter_even([1, 2, 3, 4, 5, 6, 7])# [1, 2, 3, 4, 5, 6, 7] is a parameter
Even_list
def greet(name): # 'name' is a parameter
print(f"Hello, {name}!")
greet("Jerry") # 'Jerry' is the argument passed to the 'name' parameter
Required positional arguments
Keyword arguments
*args - **kwargs
variable scope in python
Closures and Decorators
Modules
Error handling
File Handling
Inheritance
Encapsulation
Polymorphism
Abstraction
Lambda, Map, and filter higher-order function: