Skip to main content

A Python Show

Hello Readers, We are going to dive into python language which is the most in-demand technology of the current generation.

Introduction

    Python is a widely used high-level programming language. It was created by  Guido van Rossum and first released in 1991.Python is easy to use, powerful, and versatile, making it a great choice for beginners and experts alike. Its unique features allows programmers to easily understand the concepts of python  which makes them love python more than any other programming language.

Features of Python

Python has vast number of features. Let  me list a few among them.

1. Easy to code.

2. Free and Open Source.

3. Object-Oriented Language.

4. GUI Programming Support.

5. High-Level Language.

6. Extensible feature.

7. Python is Portable language.

8. Python is Integrated language.

9. Interpreted Language.

10. Large Standard Library.

11. Dynamically Typed Language.

Variables:

Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing.

How to create a variable?

To create a variable in Python, all you need to do is specify the variable name, and then assign a value to it.

<variable name>  =  <value>

example:

#integer variable

a=10


#float variable

a=3.5


#string variable

a="Ramu"


Variable assignment works from left to right. So the following will give you an syntax error.

 0 = x 

=> Output

        SyntaxError: can't assign to literal


Rules for Creating a Variable:




1. Variables names must start with a letter or an underscore.

         x = True     # valid 

         _y = True   # valid  

        9x = False  # starts with numeral 

        => SyntaxError: invalid syntax

        $y = False  # starts with symbol 

        => SyntaxError: invalid syntax


2.The remainder of your variable name may consist of letters, numbers and underscores.

        has_0_in_it = "Still Valid"

3. Names are case sensitive. 

          x = 9

         y = X*5

         =>NameError: name 'X' is not defined



Type Function:

    The Python interpreter automatically picks the most suitable built-in type for the variable while declaring it. The type function is used for showing the type of the variable.


      a = 2 

     print(type(a))

     # Output: <type 'int'>


     b = 9223372036854775807 

     print(type(b)) 

     # Output: <type 'int'>


     pi = 3.14 

     print(type(pi)) 

     # Output: <type 'float'>


    c = 'A' 

    print(type(c))

    # Output: <type 'str'>


    name = 'John Doe' 

    print(type(name)) 

    # Output: <type 'str'>



Packing and Unpacking :

You can assign multiple values to multiple variables in one line. Note that there must be the same number of arguments on the right and left sides of the = operator.

 a, b, c = 1, 2, 3 

 print(a, b, c)   # Output: 1 2 3 


a, b, c = 1, 2 

 => Traceback (most recent call last): => File "name.py", line N, in => a, b, c = 1, 2 

=> ValueError: need more than 2 values to unpack 

a, b = 1, 2, 3

 => Traceback (most recent call last): => File "name.py", line N, in => a, b = 1, 2, 3

 => ValueError: too many values to unpack


Strings

Strings in Python are arrays of bytes representing Unicode characters. It can be represented using single quotes as well as double quotes. Strings are immutable.  Python does not have a character data type, a single character is simply a string with a length of 1.



String Slicing:

You can return a range of characters by using the slice syntax. Specify the start index and the end index, separated by a colon, to return a part of the string.

b = "Hello, World!"
print(b[2:5])

Output: llo

Slice From the Start

By leaving out the start index, the range will start at the first character:

Example

Get the characters from the start to position 5 (not included):

b = "Hello, World!"
print(b[:5])
Output: "Hello"

Negative Indexing

Use negative indexes to start the slice from the end of the string:

b = "Hello, World!"
print(b[-5:-2])


Output: orl



String Concatenation:

To concatenate, or combine, two strings you can use the + operator.

a = "Hello"
b = "World"
c = a + b
print(c)


Output: HelloWorld


With Space,

a = "Hello"
b = "World"
c = a +" " +b
print(c)


Output: Hello World


Modification of String:

Strings are immutable.

S="Ramu"

S[1]="o"

TypeError: 'str' object does not support item assignment



>>> del S[1] 

 TypeError: 'str' object doesn't support item deletion .

Comments

Popular posts from this blog

JENKINS BASICS

  Jenkins  – an open source automation server which enables developers around the world to reliably build, test, and deploy their software. Dashboard: " Dashboard " is the default view shown when you open Jenkins and shows an overview of all  projects configured on a  Jenkins  instance. Creating a New Project: Step 2:  In the next screen, enter the Item name, Choose the ‘Freestyle project option’ Step 3  − The following screen will come up in which you can specify the details of the job. Note  − If you repository if hosted on Github, you can also enter the url of that repository here. In addition to this, you would need to click on the Add button for the credentials to add a user name and password to the github repository so that the code can be picked up from the remote repository. Step 4 − Now go to the Build section and click on Add build step → Execute Windows batch command Before Executing and building a file. Let me describe the task which w...

Architechture of Kubernetes

  Kubernetes Architecture and Components: It follows the client-server architecture, from a high level, a Kubernetes environment consists of a  control plane (master) , a  distributed storage system  for keeping the cluster state consistent ( etcd ), and a number of  cluster nodes (Kubelets). We will now explore the individual components of a standard Kubernetes cluster to understand the process in greater detail. What is Master Node in Kubernetes Architecture? The Kubernetes Master (Master Node) receives input from a CLI (Command-Line Interface) or UI (User Interface) via an API. These are the commands you provide to Kubernetes. You define pods, replica sets, and services that you want Kubernetes to maintain. For example, which container image to use, which ports to expose, and how many pod replicas to run. You also provide the parameters of the desired state for the application(s) running in that cluster. API Server: The  API Server  is the front-end...

NumPY In python

 NumPy Stands for numerical python How do I install NumPy? To install Python NumPy, go to your command prompt and type “pip install numpy”.  Once the installation is completed, go to your IDE (For example: PyCharm) and simply import it by typing:  “import numpy as np” Here, I have different elements that are stored in their respective memory locations. It is said to be two dimensional because it has rows as well as columns. In the above image, we have 3 columns and 4 rows available. How do I start NumPy? Single-dimensional Numpy Array: 1 2 3 import numpy as np a = np.array([ 1 , 2 , 3 ]) print (a) Output – [1 2 3] Multi-dimensional Array: 1 2 a = np.array([( 1 , 2 , 3 ),( 4 , 5 , 6 )]) print (a) O/P – [[ 1 2 3] [4 5 6]] Python NumPy Array v/s List Why NumPy is used in Python? We use python NumPy array instead of a list because of the below three reasons: Less Memory Fast Convenient The very first reason to choose python NumPy array is that it occupies less memory as co...