šPython - ZerO to HerO (BASIC Knowledge)

Hello, I'm Priya Chakraborty, a dedicated B.Tech student in Electrical Engineering at Siliguri Institute Of Technology. I'm an enthusiastic learner, constantly seeking to expand my skill set and knowledge base. With a solid foundation in programming languages such as C, R, Python, and MySQL, I'm poised to tackle complex technical challenges.
But my passions extend beyond the realm of engineering. I'm also an aspiring content writer, driven by a curiosity to communicate ideas, both technical and non-technical, in a way that captivates and educates.
My journey is defined by a relentless pursuit of self-improvement, coupled with strong communication skills. I believe in the power of continuous learning and the importance of sharing knowledge.
šWhat is Python Programming?
Python is a high-level, interpreted programming language that is known for its simplicity, readability, and ease of use. It was created by Guido van Rossum and first released in 1991.
Python is an open-source language that can be used for a variety of purposes, including web development, data analysis, machine learning, scientific computing, and more. It has a large and active community of developers who contribute to its development and maintenance.
Python's syntax is straightforward to learn, making it an excellent language for beginners. It supports multiple programming paradigms, including procedural, functional, and object-oriented programming. It also has a vast standard library that provides a wide range of built-in functions and modules for various tasks, such as working with files, networking, and data manipulation.
Python's popularity has grown rapidly in recent years due to its versatility, readability, and ease of use, as well as the increasing demand for data science and machine learning.
šWhy is it necessary to learn?
Versatility: Python is a versatile language that can be used for a wide range of applications, including web development, data analysis, machine learning, scientific computing, and more. Learning Python can open up many opportunities for you in various fields.
In-demand skill: Python is one of the most popular programming languages in the world, and its demand is only increasing. Many companies are looking for professionals who have Python skills, especially in the fields of data science and machine learning.
Easy to learn: Python has a straightforward and easy-to-learn syntax that makes it an excellent language for beginners. You can quickly get started with Python and start building your programs.
Large community: Python has a vast and active community of developers who contribute to its development and maintenance. You can find a wealth of resources, such as tutorials, documentation, and forums, to help you learn Python.
Open-source: Python is an open-source language, which means that you can use it freely and contribute to its development. This makes it an excellent language for collaborative projects and learning from others.
šLet's Start with the Basics of Python :
Topics :
Basic Print Statement
Data Types
Conditional Statements
List, String, tuple, Set, Dictionary
Loops
Function
OOPs(Basic Concept)
šPrint Statement :
In Python, the print statement is used to display the output of a program. It can be used to print strings, numbers, variables, and expressions.
print('Hello Reader !')
OUTPUT :
Hello Reader !
šData Types :
Python has several built-in data types that can be used to represent different kinds of values. Here are some of the most common data types in Python:
Numeric Types:
int: integers
float: floating-point numbers
complex: complex numbers
Boolean Type:
- bool: Boolean values (True or False)
Sequence Types:
str: strings
list: lists
tuple: tuples
Mapping Type:
- dict: dictionaries
Set Types:
- set: sets
DATA TYPES | IMMUTABLE | MUTABLE |
Numeric | ā | ā |
List | ā | ā |
String | ā | ā |
Dictionary | ā | ā |
Tuple | ā | ā |
Set | ā | ā |
šConditional Statements:
In Python, conditional statements are used to control the flow of a program based on certain conditions.
The if statement checks if a condition is True, and if it is, the code inside the if block is executed. If the condition is False, the program moves on to the elif statement (if there is one), which allows for additional conditions to be checked. If the condition in the elif statement is True, the code inside the elif block is executed. If the condition is False, the program moves on to the else statement (if there is one), which is a catch-all that is executed if all the previous conditions are False.
x = 30
if x < 0:
print("x is negative")
elif x == 0:
print("x is zero")
else:
print("x is positive")
OUTPUT:
X is positive
šList, String, tuple, Set, Dictionary :
šList:
An ordered, mutable collection of values. Lists are denoted by square brackets [].
fruits = ["apple", "banana", "cherry"]
print(fruits)
Output:
['apple', 'banana', 'cherry']
šString:
A sequence of characters. Strings are denoted by either single or double quotes (' or ") and are immutable.
greeting = "Hello, world!"
print(greeting)
Output:
Hello, world!
šTuple:
An ordered, immutable collection of values. Tuples are denoted by parentheses ().
coordinates = (10, 20)
print(coordinates)
Output:
(10, 20)
šSet:
An unordered collection of unique values. Sets are denoted by curly braces {} or by using the set() function.
numbers = {1, 2, 3, 4, 5}
print(numbers)
Output:
{1, 2, 3, 4, 5}
šDictionary:
An unordered collection of key-value pairs. Dictionaries are denoted by curly braces {} and each key-value pair is separated by a colon ':'.
person = {"name": "Alice", "age": 30}
print(person)
Output:
{'name': 'Alice', 'age': 30}
šLoops:
In Python, there are two main types of loops: for loops and while loops.
A for loop is used to iterate over a sequence of values, such as a list or a string.
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
Output:
apple
banana
cherry
A while loop is used to repeatedly execute a block of code as long as a certain condition is True. The basic syntax of a while loop is:
i = 0
while i < 5:
print(i)
i += 1
Output:
0
1
2
3
4
Loops are important constructs in programming as they allow you to repeat code without having to write it out manually for each iteration.
šFunction:
In Python, a function is a block of reusable code that performs a specific task. Functions allow you to break your code into smaller, more manageable pieces and can make your code more modular and easier to read.
Here's an example of a function that takes two numbers as input and returns their sum:
def add_numbers(num1, num2):
sum = num1 + num2
return sum
x = 3
y = 5
result = add_numbers(x, y)
print(f"The sum of {x} and {y} is {result}")
Output:
The sum of 3 and 5 is 8
šOOPs(Basic Concept)
Object-Oriented Programming (OOP) is a programming paradigm that emphasizes the concept of objects, which can contain data and code that operates on that data. Python is an object-oriented language, which means it provides support for OOP concepts such as encapsulation, inheritance, and polymorphism.
Here's an example of a simple class definition in Python:
class Car:
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
def start(self):
print("The car is starting...")
def stop(self):
print("The car is stopping...")
my_car = Car("Toyota", "Camry", 2020)
print(my_car.make)
print(my_car.model)
print(my_car.year)
my_car.start()
my_car.stop()
Output:
Toyota
Camry
2020
The car is starting...
The car is stopping...
šTOP QUESTIONS FOR BASICS OF PYTHON :
šWrite a Python program that accepts a number from the user and determines whether it is even or odd.
šWrite a Python program to find the sum of all numbers between 1 and a given number.
šWrite a Python program to find the largest element in an array.
šWrite a Python program to find the second largest element in an array.
šWrite a Python program to reverse a given string.
šWrite a Python program to find the factorial of a given number.
šWrite a Python program to check whether a given string is a palindrome or not.
šWrite a Python program to count the number of vowels in a given string.
šWrite a Python program to check whether a given number is a prime number or not.
šWrite a Python program to sort a given array in ascending order.
šWrite a Python program to check whether a given number is a palindrome or not.
šWrite a Python program to find the first N prime numbers.
šWrite a Python program to find the sum of all even numbers between 1 and a given number.
šWrite a Python program to find the sum of all odd numbers between 1 and a given number.
šWrite a Python program to calculate the area and circumference of a circle with a given radius.
šWrite a Python program to convert a given binary number to decimal.
šWrite a Python program to find the greatest common divisor (GCD) of two numbers.
šWrite a Python program to print the Fibonacci series up to a given number.
šWrite a Python program to reverse a given list.
šWrite a Python program to find the number of occurrences of a given element in a list.
šWrite a Python program to find the sum of all elements in an array.
šWrite a Python program to find the product of all elements in an array.
šWrite a Python program to find the largest and smallest element in an array.
šWrite a Python program to find the missing number in a given array of integers.
šWrite a Python program to remove duplicates from a given list.
šWrite a Python program to count the number of words in a given string.
šWrite a Python program to check whether two strings are anagrams or not.
šWrite a Python program to find the length of the longest substring without repeating characters in a given string.
šWrite a Python program to find the median of a given list of numbers.
šWrite a Python program to check whether a given string is a pangram or not.
šWrite a Python program to sort a given list of integers in descending order.
šWrite a Python program to find the sum of the digits of a given number.
šWrite a Python program to find the length of the longest increasing subsequence of a given list of integers.
šWrite a Python program to find the common elements between two given lists.
šWrite a Python program to find the second smallest element in a given list.
šWrite a Python program to find the sum of all elements in a given matrix.
šWrite a Python program to find the transpose of a given matrix.
šWrite a Python program to check whether a given number is a perfect number or not.
šWrite a Python program to find the ASCII value of a given character.
šWrite a Python program to find the area of a triangle given its base and height.
šWrite a Python program to find the common elements between three given lists.
šWrite a Python program to reverse a given integer number.
šWrite a Python program to find the length of the longest palindrome substring in a given string.
šWrite a Python program to find the second-largest element in a given dictionary.
šWrite a Python program to find the sum of all prime numbers between two given numbers.
šWrite a Python program to check whether a given year is a leap year or not.
šWrite a Python program to find the sum of all elements in a given set.
šWrite a Python program to check whether a given number is an Armstrong number or not.
šWrite a Python program to find the factorial of a given number using recursion.
šWrite a Python program to find the median of a given list of numbers without using the built-in function.
šWrite a Python program to find the sum of all elements in a given tuple.
šWrite a Python program to find the first non-repeating character in a given string.
šWrite a Python program to find the number of vowels and consonants in a given string.
šWrite a Python program to find the sum of all elements in a given dictionary.
šWrite a Python program to find the number of words that start with a vowel in a given string.
šWrite a Python program to check whether a given string is a palindrome or not without using the built-in function.
šWrite a Python program to find the sum of all elements in a given nested list.
šWrite a Python program to check whether a given number is a perfect square or not.
šWrite a Python program to generate all possible permutations of a given string.
šWrite a Python program to find the sum of all elements in a given two-dimensional array.
šWrite a Python program to find the maximum and minimum values in a given list of tuples.
šWrite a Python program to find the first duplicate element in a given array.
šWrite a Python program to count the number of occurrences of a given element in a given list.
šWrite a Python program to find the largest palindrome made from the product of two n-digit numbers.
šWrite a Python program to check whether a given string is a substring of another given string.
šWrite a Python program to find the sum of all even numbers in a given list.
šWrite a Python program to find the maximum occurring character in a given string.
šWrite a Python program to find the number of even and odd elements in a given list.
šWrite a Python program to find the area of a circle given its radius.
šWrite a Python program to find the sum of the first n prime numbers.
āļøIf you are a beginner and want to know more about Python programming, you can read my Basics of Python blogs (From part 1 to part 15).
Basics of Python-1 -
Print StatementBasics of Python-2 -
Data TypesBasics of Python-3 -
Conditional StatementBasics of Python-4 -
ListBasics of Python-5 -
StringBasics of Python-6 -
TupleBasics of Python-7 -
SetBasics of Python-8 -
DictionaryBasics of Python-9 -
LoopsBasics of Python-10 -
For loopBasics of Python-11 -
Pattern PrintingBasics of Python-12 -
While LoopBasics of Python-13 -
FunctionBasics of Python-14 -
OOPs Concept
Here you will get to know in detail about the topic I have discussed earlier.




