Posts

Showing posts from June, 2020

Python Sets

                                 Sets A set is a collection of data which is unordered and unindexed. We represents sets with curly braces { }. In sets duplicate items are not allowed.  E.g. set1 = {'apple', 'mango', 'orange' } Items in set are unindexed which means you can not access the item individually from the set using its index. But we can loop through the set. E.g. for i in set1:           print(i)        #output : apple                       mango                  orange set() method is used to define the set. E.g. set2 = set(['one', 'two', 'three'])     print(type(set2))      # output : set In set we can have any type of data but it should be immutable means the data which does not cha...

Python Tuples

                                 Tuples Just like list in Python, Tuple is also used to store the data but the difference is that tuples are unchangeable. Tuples are also ordered. We use round brackets or paranthesis to represent tuple.  E.g. tup1 = ('one', 'two', 'three') Tuple is indexed same as lists. We can access the elements of tuple by using index strtaing from 0. E.g. print(tup1[1])          # output : two Negative indexing means we start from the end of tuple just like list. -1 means last element, -2 means secod last and so on. E.g.    tup2 = (10, 25, 31, 36, 67)     print(tup2[-1])        #output : 67     print(tup2[-3])        #output : 31 To check the length of tuple we can use len() method. E.g. len(tup2)          # output : 5 As we already discussed that tuplea are...

Python Lists

                         Python Lists List is a ordered, indexed and changeable collections of data. List can have heterogenous data type. In python we represent list with square brackets [ ].  Example of list : fruits = ['apple', 'banana', 'mango']              items = ['table', 12, 3.13, 'tree'] Index of list starts from 0. We can check the length if list using len( ) function.  E.g.  numbers = [45, 52, 23, 87]     len(numbers)     # output : 4       numbers[0]        # output : 45      numbers[2]        # output : 23 If we want to access the list from last element and do not know the length then we can use negative indexing. -1 index is of last element, -2 index is of second last and so on.  E.g. numbers[-1]      #output : 87    numbers[-3]...

Data Types

                            Data Types As the name suggests, data type means the type of data you are using like integer, string, float, array etc. Variable is used to hold any type of data. In Python, you do not need to define the type of variable, just assign the value to it and it will automatically be declared as that type of data. In python to check the data type of variable, type() function is used. For e.g. :                    x = 10                type(x)           # int                y = "Hello"                type(y)           # str In python there are many data types like any other programming language. But there are 5 standard data type: Numbers : Number stores numeric values. ...

Python Variables

                     Python Variables Variable is used to store the values. Basically we can think of variable as a container which contains the value like number, string, boolean, etc. Variables are also called as identifier because they are used to identify a particular value. In other programming languages, before assigning a value to variable you have to declare the varibable with its data type like whether it is integer, string, float or any other. But in Python you don't have to do this. Just pick the name of variable and assign the value. The type of variable is automatically detected in Python. Python is smart right. We can even change the data type of variable after they have been set. Suppose you make a varable x and assign the integer value to it, but after some time you are giving string value to the same variable then the type of variable will be change from int to string. I told you Python is smart. For example : ...

Python Syntax

Image
                           Python Syntax The syntax or code writing style of Python is very easy. It is somewhat similar to writing code in english language. This is the speciality of Python that we can execute large tasks in less line of code as comapred to other languages. For example, suppose you want to write a code of  "Hello World". In C or Java you have import some libraries first and then make a function (in C) or class (in JAVA) and then write the code in that particular block. But in Python you can make this program in single line like,                              As you can see you saved your time in Python. Only single line of code and you get the result. In above example, I used the Python Shell to execute the line, but we can also make python script also. Just create a file with .py extension and write your code in that file...

Python Installation

Image
                                        Python Installation Python comes in 2 versions mainly Python 3 and Python 2. Currently Python 2 is in EOL (End of Life) status. There will be no further updates and bug fixes. Python 3 is the recommending version to install. In Python 3 also, currently Python 3.8.3 is latest update.  To install the Python you can visit the https://www.python.org/downloads/ , here you can find all the downloads for python. Python supports the download for many different platforms like Windows, Mac-OS, Linux, Solaris, iOS and iPad-OS and many more. Just click on Download Python button after selecting your platform and your downloading will start. Installation for Windows :  After downloading double click on the downloaded file and start your installation. Just follow the normal installation procedure and Python will install in your system. While install...

Python Introduction

                                                What is Python ?  Introduction :  I am sure you have already heard about Python. It is a high-level, interpreted programming language created by Guido Van Rossum. Python was developed as a hobby project by Guido Van Rossum in December 1989 which can keep him occupied during the week around Christmas. It was first released in 1991. Yes Python was created before Java. But why is it becoming famous now? Maybe because of the rising of fields like AI, Machine Learning and Data Science. Definitely Java is more faster language than Python but the syntax of Python is more simpler. It is somewhat like English language. Today Python is used in many different areas like Machine Learning, Data Science, Web development, Game Development, Software development.  There are 2 versions of Python : Python 2 and Python 3. ...