Technical

Crash Course on Python Programming

Crash Course on python Programming
Written by anjali

Crash Course on Python Programming

Python is a computer programming  language and it can be used to build web applications on a server.

Features of Python

  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.

Python can be used as:

1.Web applications can be developed on a server using Python.
2.Workflows can be made with Python and other technologies.
3.Database systems are connectable with Python. Files can also be read and changed by it.
4.Big data management and advanced mathematical operations can both be done with Python.
5.Python can be used to produce software that is ready for production or for rapid prototyping.

Python Syntax:

>print(“Hello”)
      Hello

Python Indentation

The spaces at the start of a code line are known as indentation.

Python’s indentation is crucial, unlike other programming languages where it just serves to make the code easier to understand.

A block of code is indicated via indentation in Python.

Comments

Python offers the ability to add comments for in-code documentation.

When a comment begins with a #, Python will treat the remaining characters in the line as comment

Python code can be explained using comments.

Code can be made more readable by using comments.

When testing code, comments can be used to stop execution.

#This is a comment.
print(“Hello”)

Variables

Data values are kept in variables as storage.Declaring a variable is not a command available in Python.When a variable is initially given a value, it is considered to have been formed.

x = 1
y = “Anjali”
print(x)
print(y)

Casting

Casting can be used to define a variable’s data type if you want to.

 Also Read: About Python programming

Variable Names

A variable’s name might be short (like x and y) or longer (like age, carname, or total volume). Python variable rules:
1.The underscore character or a letter must come first in a variable name.
2.No number may begin a variable name.
3.Only underscores (A-z, 0-9, and _) and alphanumeric characters are permitted in variable names.
4.Names of variables are case-sensitive (age, Age and AGE are three different variables)

Global Variables

Global variables are those that are produced outside of a function, like in all of the aforementioned cases.

Everyone can utilise global variables, both inside and outside of functions.

Global Keyword

Normally, a variable created within a function is considered local and can only be utilised within that function.

Use the global keyword to define a global variable within a function.

Python Data Types

Built-in

Different forms of data can be stored in variables, and different types can perform various functions.

The following categories of data types are included by default in Python:

Text Type: str
Numeric Types: intfloatcomplex
Sequence Types: listtuplerange
Mapping Type: dict
Set Types: set
Boolean Type: bool
Binary Types: bytes
None Type: NoneType

 

Python Numbers

In Python, there are three types of numbers:

  • int
  • float
  • complex

Int:A full number, positive or negative, without decimals, and with an indefinite length is known as a “integer.”

float:A number with one or more decimals, whether positive or negative, is referred to as a float

complex: The imaginary portion of complex numbers is represented by the letter “a”.

Random Number

Although Python does not have a built-in random() function, it does contain a random module that can be used to generate random numbers.

Python Strings

In Python, strings are enclosed in either single or double quotation marks.

Slicing Strings

The slice syntax allows you to return a range of characters.

To return a portion of the string, enter the start index and the end index, separated by a colon.

Modify Strings

Upper Case

The string is returned by the upper() method in all caps.

Lower Case

Lowercase letters are returned by the lower() method.

Remove Whitespace

Whitespace is the blank space that appears before and/or after the actual text, and you should usually eliminate it.

Replace String

A string is replaced with another string using the replace() method

Split String

The text between the chosen separator is used as the list elements when the split() method returns a list.

String Concatenation

Use the + operator to concatenate, or merge, two strings.

String Format

We discovered that we cannot combine strings and numbers in this way in the Python Variables .

But by utilising the format() technique, we can combine texts and numbers!

The given arguments are formatted using the format() method, which also inserts them into the string in the appropriate placeholders.

Escape Character

Use an escape character to inserted prohibited characters into a string.

Backslashes and the character you want to insert are considered escape characters.

A double quotation inside a string that is surrounded by double quotes is an illustration of an unlawful character.

String Methods

You can use a variety of built-in methods on strings in Python.

Booleans

You frequently need to know whether an expression in programming is True or False.

In Python, you may evaluate any expression to see whether it is True or False.

Python Operators

Operations on variables and values are carried out using operators.

The + operator is used to combine two values in the example below.

The operators in Python are split into the following categories:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Identity operators
  • Membership operators
  • Bitwise operators

Arithmetic Operators: Common mathematical procedures are carried out using arithmetic operators and numeric quantities.

Assignment Operators:  To assign values to variables, utilise assignment operators.

Comparison Operators:  To compare two values, comparison operators are employed.

Logical Operators: Conditional statements are combined using logical operators.

 Identity Operators: Identity operators are used to compare objects to determine if they are the same object in the same memory address rather than if they are equal.

Membership Operators: To determine whether a sequence is contained in an object, membership operators are employed.

Bitwise Operators:  Binary number comparisons are performed using bitwise operators.

Also Read :About Eclipse

About the author

anjali

Leave a Comment