Posts

Python 3.6 - Points to remember

  Points to remember ·          A variable is any location in the computer’s memory which holds a value. ·          Python is memory efficient when dealing with variables as compared to other programming languages. ·          An identifier is a name given to a variable, function, class, list, tuple etc. Identifiers are used to identify things in Python. ·          Keywords are reserved words in Python that have some special meaning and they can only be used for pre-defined purpose. ·          Comments are always used to describe the features of a program and ignored by Python compiler and interpreter. ·          ‘#’ symbol is used to create a single line comment.    ·          Pyth...

Python 3.5 - Constants and literals

Image
  Constants A constant is a variable whose value can never be changed during the execution of program. We know that, the value of a variable can be changed anytime in a program. But if the variable is a constant and if once we assigned a value to it, then its value can never be changed later in the program. In languages like C, C++ and Java, you may have worked with constants but Python does not have concept of constants. We cannot create constants in Python. But you can indicate a variable as constant by writing its name in all capital letters so that you will remember that it is a constant and I should not change the value of it. But again you can change its value. This is just so that you remember that it is a constant. You can indicate a variable as constant. For example – MAX_VALUE, PIE etc. can be treated as constants. age = 28 # a variable PIE = 3.14 # we indicate the variable as constant but we can change its value later  You can use a variable as constant wh...

Python 3.4 - Indexing and slicing

Image
  Indexing and slicing   Indexing and slicing are two approaches, used to access or retrieve elements of a sequence datatype such as string, list, tuple etc. Indexing Indexing is used to access a single element at a time. We can use index number of an element of a sequence to access that particular element. Every element in a sequence such as string, list, tuple, bytes etc. has an index number. An index number starts from 0 (zero) in Python. So an index number is used to access an element . For example, in a string “india” the index number of first element ‘i’ is 0, the index number of second element ‘n’ is 1, the index number of third element ‘d’ is 2 and so on. The index number of last element ‘a’ is 4. So remember that, the indexing starts from 0 and ends at n-1 in a sequence of n length. In our case, string “india” has length 5 i.e. 5 characters or elements. So the indexing started from 0 and ended at 4 (n-1 or 5-1). Same concept applies to all the other sequences. S...

Python 3.3 - Datatypes in Python

Image
  Datatypes in Python As we have already discussed that data type refers to the type of data. So datatype implies that what type of data we can store in our Python program. There are two categories of datatypes available in Python – Built-in data types and User defined data types Built-in data types The data types which are pre-defined in Python are called built-in data types. These data types have already been developed by Python developer team which we can use directly. So we do not need to do anything in it. Following are built-in data types – ·          None ·          Numbers ·          Boolean ·          Sequences ·          Sets ·          Dictionary   These datatypes are further classified in some more datatypes...

Python 3.2 - Comments in Python

  Comments Comments are always used for programmer’s convenience in any programming language. A comment is used to describe the features of a program . When we write program then we can write comments for classes, functions, statements etc. Comments help to understand the code easily. For example, you are working in a software company. You wrote a program of ten thousand lines. After some time, you left the job and a new programmer joined the company. Now the new programmer opens the file which you had written. So before proceeding he has to understand the code first so that he can continue. Now, if you used proper comments in your program then the new guy can understand it very easily and it will take very less time. But if you did not use proper comments in your program then the new programmer will have a lot of difficulties understanding what and why you have written this. So it will waste the time because the new programmer has to understand the whole lengthy code of 10000 li...