Python Basics
PYTHON
"Python is a high-level programming language. It is also known as an interpreted language because it executes code line by line, rather than compiling the entire program at once."
The Variables are used to hold the values of different data types in Python. There are primarily two types of variables in most programming languages. The local variable and the Global variable.
Local variable
The local varible is only defined with in the the specific functions. The local variable in a program doesn't hold any value outside the function in a program.
y=20
def add(a,b):
c=a+b
return c
sum=add(x,y)
print(sum)
// here the variables a,b are local variables
Global Variable
The Global Variable is the variable which is defined for the whole program it will work in every function.
y=20
def add(a,b):
c=a+b
return c
sum=add(x,y)
print(sum)
// Here the variables x and y are global variables
Data Types
"Data types define the kind of value a variable can hold. They determine the operations that can be performed on the variable.A variable can be of numeric data type(int,float,complex),String Data type etc.
"In Python, you don't need to explicitly declare the data type of a variable, unlike in languages like C and C++."
There are mainly 6 Types of Data type:
Numeric
String
List
Boolean
Tuple
Dictionary
Numeric Data Type
Numeric data types represent numbers. They are further classified into two categories:
- Integer: Whole numbers (e.g., 10, -5, 0)
- Float: Decimal numbers (e.g., 3.14, -2.5)
String Data Type
A sequence of characters enclosed in single or double quotes.
Example: "Hello, World!"
Boolean Data Type
Represents either True or False.
Example: True, False
List Data Type
An ordered collection of items, enclosed in square brackets.
Example: [1, 2, 3, "apple", "banana"]
Dictionary Data Type
An unordered collection of key-value pairs, enclosed in curly braces.
Example: {"name": "Alice", "age": 30, "city": "New York"}
Tuple Data Type
An ordered, immutable collection of items, enclosed in parentheses.
Example: (10, 20, 30, "Python")
Comments
Post a Comment