Python Fundamentals | Most Easiest and Powerful Language | Python Programming Article Series - Part 02

Python Fundamentals | Most Easiest and Powerful Language in the Industry of Technology | Python Programming Series-02

Python Fundamentals | Most Easiest and Powerful Language in the Industry of Technology | Python Programming Series-02
We will be learning and going through the following topics of Python programming language in our 2nd Python Programming article:
  1. Swapping in Python
  2. Changing values in Python
  3. Delete variable from memory in Python
  4. Complex equations in Python
  5. Array in Python
  6. String concatenation in Python
  7. List in Python
  8. Tuples in Python
  9. Sets in Python
  10. Dictionary in Python
  11. Identifiers - Naming conventions
  12. Data types conversions in Python
  13. Operators in Python


SWAPPING IN PYTHON

Swapping refers to the process of assigning a value of one variable to another and wise versa. Swapping requires a bunch of lines of code in other programming languages. But Python made our lives easier by providing a simple and easy method of swapping. You can simply swap the values of two variables in python as shown below:

    #Assigning values for swapping
    var1, var2 = 5, 6

    #Swapping values
    var1, var2 = var2, var1


 PRACTICAL:

You can have a look at practical implementation of swapping code in Python IDE:


Swapping in Python
Swapping in Python





CHANGE VALUES OF VARIABLES IN PYTHON

Changing values of variables in python is quite simple and easy. Python allows us to simply assign any value of any data type to the variable and again change it. The snippet below shows how we can assign and change values of a variable in python at run-time. 

Change values of variables in Python
Change values of variables in Python



DELETE VALUES FROM MEMORY IN PYTHON

Deleting values from memory in python deletes the value of a variable permanently, until a new value is assigned. Syntax for deleting values from memory in python is as follows:

    #It will delete the value stored in variable x
    del x


PRACTICAL:

Here is the practical implementation of deleting a value from the memory in python, on python IDE:

Deleting values from memory in Python
Deleting values from memory in Python

 



SOLVING COMPLEX EQUATION IN PYTHON

Python is capable of dealing with complex equations having real as well as complex numbers. It provides an easiest and simplest method for solving complex equations. You can perform any operation among the equations without making your code lengthy and harder. The syntax for typing a complex equation is as follows:

    #Here 5 is a real, while 10 is a complex number
    5 + 10j


PRACTICAL:

You can see the practical implementation of solving a complex equation, which includes addition, subtraction, multiplication, and division operations.

Solving complex equations in Python
Solving complex equations in Python

 


STRING CONCATENATION IN PYTHON

String concatenation syntax is almost same as in other programming languages have. String concatenation combines two or more strings together. The syntax is pretty simple:

    #Either you can use the names of the variables
    var1 + var2
    #Or simply insert string between using + sign
    print (var1 + 'Howtechyy')

PRACTICAL:

Lets see how we can concatenate strings in Python:

String concatenation in Python
String concatenation in Python



String concatenation in Python
String concatenation in Python

 


LIST IN PYTHON

Lists in Python are very useful and easy to use. It is also considered to be a data type in python. The basic syntax of declaring a list is as follows:

    listName = [value01,value02,value03,value04,value05, ...]

"listName" stands for the name you will assign to the list of variables or values. Lists in Python are quite dynamic. You can have any sort of variable in your list ranging from integers to strings.

    myList = [5, 2, 'Howtechyy', False, 8, ...]


As discussed above, Lists are also considered to be data types in python, therefore, it is also possible to insert one lists into another or to concatenate them.

    myList = [5, 2, 'Howtechyy', [5,9,'list', True], 4]

 Now,  
  • what if you want to print your list? 
  • print any element of list? 
  • Or concatenate lists?
 

ELEMENTS OF A LIST IN PYTHON

The syntax for printing any element of a list, entire list, or concatenating lists is as follows:

    #This will print your entire list
    print (listName)
    #This will print an element of your list
    #Index_Number stands for the position of the element(starts with 0).
    listName[index_number]
    #This will concatenate the lists
    print (listName1 + listName2)

  


PRACTICAL:

Lets see this in a more practical environment:

Lists in Python
Lists in Python



UPDATING A LIST IN PYTHON

Updating a list in python is very useful and dynamic feature in lists of Python. The syntax for updating a value in the list is as follows:

     #index_number should be specified where you want to insert
    listName[index_number] = value

 

PRACTICAL:

Try this in a Python IDE:

Updating lists in Python
Updating lists in Python




TUPLES IN PYTHON 

Tuples are similar to lists in Python. There are only two major differences among Lists and Tuples:
  1. Values in Tuples can not be updated
  2. Parenthesis are used instead of square brackets

 SYNTAX:

    listName = (1,4,True,'HowTechyy')



PRACTICAL:

Try this in a Python IDE:

Tuples in Python
Tuples in Python




SET IN PYTHON

Sets in Python are also one of kind of tuple. Curly brakets ({}) are used to inialize set.

    setName = {value1, value2, value3 ...}

PRACTICAL:

Try this in a Python IDE:

Set in Python





DICTIONARY IN PYTHON

Dictionary in Python are composed of keys and values. In a dictionary of Python you can store different values of things along with their names. There are two ways of using dictionary in Python. Syntax for first method is as follows:

    #declaring dictionary
    dictionaryName = {}
    #Filling it up
    dictionaryName['Key'] = 'Value'
      dictionaryName['Key2'] = 'Value2'
      #and so on
      #For Printing
      Print (dictionaryName)


PRACTICAL:

Lets try this is in a practical environment:


Dictionary in Python
Dictionary in Python


However, another method's syntax is as follows:

    dictionaryName = {'key':'value', 'key2':'value2', 'key3':'value3'}

This method is more used and easy to work with. Lets have a look at its implementation in Python programming.

PRACTICAL:


Dictionary in Python
Dictionary in Python


You can also print all keys separately and the values, as well. Use the following syntax to get keys and values separately:

    #For printing all keys
    dictionaryName.keys()
    #For printing all values
    dictionaryName.values() 

IMPLEMENTATION:


Dictionary in Python
Dictionary in Python



IDENTIFIERS - NAMING CONVENTIONS IN PYTHON

There are a few important points to note and apply in your Python programming regarding naming conventions in Python:
  • A variable name should start with a small letter except name of a classes.
  • Using an underscore sign ("_") indicates a private identifier
  • Using double underscore sign ("__") indicates the highest level of privacy of identifier. 
 

DATA TYPE CONVERSION IN PYTHON

Data type conversions or casting in python is a lot easier than any other programming language. The syntax for conversion is as follows. You can simply insert any type of value into the data type method in which you want to convert it.
  • int(value) 
  • float(value)
  • str(value)
  • list(value)
  • tuple(value)
  • chr(value)
  • hex(value)
  • oct(value)
  • bin(value)       



OPERATORS IN PYTHON

The major types of operators used in python is as follows:
  • Arithmetic operators (+,-,*,/,**,//)  
  • Assignment operators (=, +=, *=, /=, -=)
  • Comparison operators (==, !=, <, >)
  • Logical operators (or, and, not)
  • Bitwise operators
  • Identity operators (is, is not)
  • Membership operators (in, not in)




Click for previous: part 01 of Python Fundamentals: 
Python Fundamentals | Most Easiest and Powerful Language | Python Programming Article Series - Part 01

Post a Comment

0 Comments