Python Basics

Basics of Python Programming


Introduction to Python


Python is an easy to learn and very powerful programming language. It has efficient data structures and a simple approach to object-oriented programming. Python’s syntax together with its interpreted nature, make it an ideal language for scripting and rapid application development.

Getting Started

  • To start coding in Python, you'll need a Python interpreter. 
  • The Python interpreter and the python standard library are freely available for all major platforms from the Python’s official web site, https://www.python.org/.

How to run Python program using IDLE software?


Executing Python Program using IDLE


Python Basics


Python basics are the fundamental building blocks of the Python programming language. These basics are essential for understanding and writing Python code. Here are the key topics that come under Python basics:
  • Syntax: This refers to the rules that define how Python code is written. It covers things like indentation, keywords, and operators.
  • Variables: Variables are used to store data in your programs. You can give them meaningful names and assign them different data types like numbers, text, or lists.
  • Data Types: Python has various built-in data types to represent different kinds of data. Some of the common data types include:
    • Integers: Whole numbers (e.g., 1, 2, 3)
    • Floats: Numbers with decimal points (e.g., 3.14, -5.2)
    • Strings: Text data (e.g., "Hello, world!", 'This is a string')
    • Booleans: Logical values (True or False)
    • Lists: Ordered collections of items (e.g., [1, 2, 3], ["apple", "banana", "cherry"])
    • Dictionaries: Unordered collections of key-value pairs (e.g., {"name": "Purva", "age": 20})
  • Operators: Operators are used to perform operations on data. Python provides various operators like arithmetic operators (+, -, *, /), comparison operators (==, !=, <, >), and logical operators (and, or, not).
  • Control Flow Statements: These statements control the flow of execution of your code. They allow you to make decisions (using if statements) and repeat code blocks (using loops like for and while).
  • Functions: Functions are reusable blocks of code that perform a specific task. You can define functions with parameters and a return value.
  • Comments: Comments are lines of code that are ignored by the Python interpreter. They are used to explain your code and make it more readable for others.
By mastering these Python basics, you'll have a solid foundation for building more complex Python programs.

Why it is called Python?

Python programming language was originally designed by Guido van Rossum. When he began implementing Python, he was also reading the scripts from “Monty Python’s Flying Circus” (a BBC comedy series). He wanted a short, unique, and slightly mysterious name of language, so he decided to call the language Python. Python computer language has nothing to do with reptiles (pythons).


Type of Software that you can developed using Python


Use of Comments in Python

It is good practice to write comments in program code. In the header part of your program, you can write your name, date of program and practical definition. Comments are also used to describe the program logic.

Many of the python Practicals in this site include comments.
  • # (hash) is the character used for Comments in Python. Any line started with # in Python code is considered as a comment line.
  • A comment may appear at the start of a line but not within a string literal. A # character within a string literal is just a hash character.
  • Comments are used to describe the code and are not interpreted by Python.

Example of Comments in Python

# This is the sample comment.
# Program is developed by K Patel. Date: 20-May-2024
# Definition: Python program to print Hello World.

print ("Hello Python Practicals")

Output of above code:

Hello Python Practicals

Following # is not a comment as it is written inside a string

>>> print ("#Hello Python Practicals")
#Hello Python Practicals

Let's begin with Python Numbers 


No comments:

Post a Comment