Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
39 views

Python Basic

The document provides an overview of the Python programming language. It discusses that Python is a high-level, dynamically typed language created by Guido van Rossum in 1991. It then explains that Python is popular for data science due to its large library of tools for tasks like data manipulation, visualization, and machine learning. Key features of Python include being high-level, interpreted, dynamically typed, having a standard library and being extensible. The document also covers Python concepts like variables, keywords, datatypes, operators, conditional statements, and loops.

Uploaded by

bizzpy n
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Python Basic

The document provides an overview of the Python programming language. It discusses that Python is a high-level, dynamically typed language created by Guido van Rossum in 1991. It then explains that Python is popular for data science due to its large library of tools for tasks like data manipulation, visualization, and machine learning. Key features of Python include being high-level, interpreted, dynamically typed, having a standard library and being extensible. The document also covers Python concepts like variables, keywords, datatypes, operators, conditional statements, and loops.

Uploaded by

bizzpy n
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Python Basic

Introduction
Python is described as a high-level, interpreted, dynamically typed programming
language.
● It was created by Guido van Rossum and first released in 1991.
Python's syntax is designed to be readable and concise, emphasizing code readability
and simplicity.

Python in Data Science


Python has grown to be one of the most widely used programming languages in the
data science industry because of its adaptability, large library, and simplicity of use. It
provides a wide range of data-related tasks with a great ecosystem of tools and
frameworks. Here are some of the main explanations for why Python is so popular in
data science:
1. Libraries for Manipulating Data Pandas, one of Python's potent modules, offers
data structures and functions for quickly modifying and analysing massive
datasets. Because Pandas supports data cleansing, transformation, filtering, and
merging, it is a crucial tool in workflows for data scientists.
2. Scientific and mathematical computing: Libraries like SciPy and NumPy offer
crucial features for mathematical and scientific computations. Multi-dimensional
arrays can be used and mathematical operations performed on them using
NumPy, whereas SciPy expands these capabilities with extra scientific tools and
methods.
3. Visualization: Python provides a number of visualization libraries that aid in the
creation of illuminating plots, charts, and graphs, such as Matplotlib, Seaborn,
and Plotly. For data exploration, analysis, and result display, these libraries are
necessary.
4. Machine learning: Python is a go-to language for developing predictive models
and data-driven solutions since it includes a wealth of libraries and frameworks
for machine learning. Scikit-learn, TensorFlow, Keras, and PyTorch are a few
well-known machine learning libraries.
5. Integration with Other Technologies: Big data processing frameworks like
Apache Spark, cloud services, databases, and other tools and technologies
frequently used in data science may all be easily integrated with Python.
6. Open Source and Free: Python is open-source and most of its data science
libraries are free to use, which makes it widely accessible and promotes adoption
in a variety of industries.

Key features of Python

● High-level Language: Python is a high-level programming language, which


implies that it offers abstractions that obscure the hardware of the computer in
its low-level aspects. It is simpler to communicate ideas in a way that is readable
to humans since programmers can work with more abstract concepts.

● Python is an interpreted language, which means that the Python interpreter at


runtime executes the code line by line. Unlike languages like C++ or Java, it
doesn't need a separate compilation phase.

● Dynamically Typed: Python is dynamically typed, indicating that variable types


are determined at runtime based on the values assigned to them. Unlike
statically-typed languages, you don't need to explicitly declare the type of a
variable before using it.

● Standard Library: Python comes with an extensive standard library that includes
a wide range of modules and packages. These modules provide pre-built
functionalities for tasks like file I/O, networking, data manipulation, and more,
enhancing code reusability and simplifying development.

● Extensibility and Integration: Python can be easily integrated with other


languages like C, C++, and Java, enabling developers to leverage existing
codebases and libraries from different languages.

Variables
A variable in Python is the name of a place in memory where data is kept. It serves as a
container to store manipulable and useful values for the programme. Because Python is
dynamically typed, unlike some other programming languages, you are not required to
explicitly specify the data type of a variable. Using the variable's value as a starting
point, the data type is deduced.
Declaring a variable
Using the create variable command, you may provide a variable a name and a value.
Variable Naming Rules:
● Variable names can only contain letters (a-z, A-Z), digits (0-9), and underscores
(_).
● The first character of a variable name cannot be a numeric character
● Variable names are case-sensitive (e.g., age, Age, and AGE are three different
variables).
● Avoid using reserved keywords as variable names (e.g., if, while, for, and, etc.).

Keywords
Keywords in Python are reserved words that have specific meanings and functionalities
within the Python language. These words cannot be used as identifiers (variable names,
function names, etc.) because they are already predefined and serve specific purposes
in the language's syntax and semantics.

Example = True ,False, if , else, for , while etc.

Datatype in python
Datatypes in Python refer to the categorization of data based on its nature and the
operations that can be performed on it. Python is a dynamically typed language,
meaning the data type of a variable is determined at runtime based on the value
assigned to it. Here are some common data types.
Type of datatype :

1. Integer
2. Float
3. Boolean
4. String
5. List
6. Tuple
7. Set
8. Dictionary

● Built in data type


1. int: Integer data type, e.g., 1, -5, 1000
2. float: Floating-point data type, e.g., 3.14, -2.718, 0.0.
3. str: String data type, e.g., "Hello, World!", 'Python', "42"
4. bool: Represents a Boolean value, either True or False
● User define
1) list: Ordered and mutable collection of elements, e.g., [1, 2, 3], ['apple', 'banana',
'cherry'].
2) tuple: Ordered and immutable collection of elements, e.g., (1, 2, 3), ('a', 'b', 'c').
3) dict: An unordered collection of key-value pairs, e.g., {'name': 'John', 'age': 30}.
4) set: An unordered collection of unique elements, e.g., {1, 2, 3}, {'apple', 'banana',
'cherry'}.

Type Casting
Type casting, also known as type conversion, refers to the process of converting a
variable from one data type to another. Python provides built-in functions that allow you
to perform typecasting between compatible data types.

Operators
Operators in Python are special symbols or characters used to perform various
operations on variables and values. Python supports a wide range of operators, which
can be categorized into several groups:

Types of operators
1. Arithmetic
2. Comparison
3. Logical
4. Identity
5. Membership
6. Assignment

Conditional statements, also known as control structures or decision-making


constructs, are fundamental in programming. They allow you to create flexible programs
that can make decisions based on specific conditions. In Python, as well as many other
programming languages, conditional statements are key to implementing logic and
determining which blocks of code to execute.
The basic concept of a conditional statement is to evaluate a condition (a boolean
expression that is either True or False and execute different code blocks based on the
result. Here's the general structure of conditional statements:

Decision-Making:
● Conditional statements provide the ability to make decisions in code based on
certain condition.
● When the condition is True, the code block under the if or elif (if used) is
executed.
● When the condition is False, the code block under the else (if used) is executed,
or the program continues to the next part of the code.

Loops in Python
Loops are significant programming control structures that let us run a block of code
repeatedly until a certain condition is satisfied. They assist in handling vast amounts of
data effectively and minimizing repetitive operations.
Types of loops
● for loop
● While loop
For loop-
The for loop is used when you know how many iterations there will be or when you want
to loop through a sequence of elements (such as a list, tuple, or string).
It performs a code block execution for each iteration while iterating over a sequence,
adding each element to a variable.
example-
s = [1,2,3]
for i in s:
print(fruit)

While loop:
The while loop is used when the number of iterations is unknown in advance, and the
loop continues as long as a defined condition remains True.
It executes the code block periodically as long as the condition is true.
Example-
count = 0
while count < 5:
print("Count:", count)
count += 1

You might also like