
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Mohd Mohtashim has Published 238 Articles

Mohd Mohtashim
2K+ Views
Lists respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new list, not a string.In fact, lists respond to all of the general sequence operations we used on strings in the prior chapter.Python ExpressionResultsDescriptionlen([1, 2, 3])3Length[1, ... Read More

Mohd Mohtashim
344 Views
To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting or the remove() method if you do not know.Example Live Demo#!/usr/bin/python list1 = ['physics', 'chemistry', 1997, 2000]; print list1 del list1[2]; print "After deleting value at index 2 : " ... Read More

Mohd Mohtashim
477 Views
To access values in lists, use the square brackets for slicing along with the index or indices to obtain value available at that index.Example Live Demo#!/usr/bin/python list1 = ['physics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3, 4, 5, 6, 7 ]; print "list1[0]: ", list1[0] print "list2[1:5]: ", list2[1:5]OutputWhen the ... Read More

Mohd Mohtashim
4K+ Views
Python includes the following built-in methods to manipulate strings −Sr.NoFunction & Description1capitalize()Capitalizes first letter of string2center(width, fillchar)Returns a space-padded string with the original string centered to a total of width columns.3count(str, beg= 0, end=len(string))Counts how many times str occurs in string or in a substring of string if starting index ... Read More

Mohd Mohtashim
3K+ Views
Normal strings in Python are stored internally as 8-bit ASCII, while Unicode strings are stored as 16-bit Unicode. This allows for a more varied set of characters, including special characters from most languages in the world. I'll restrict my treatment of Unicode strings to the following −Example Live Demo#!/usr/bin/python print u'Hello, ... Read More

Mohd Mohtashim
6K+ Views
Python's triple quotes comes to the rescue by allowing strings to span multiple lines, including verbatim NEWLINEs, TABs, and any other special characters.The syntax for triple quotes consists of three consecutive single or double quotes.Example Live Demo#!/usr/bin/python para_str = """this is a long string that is made up of several lines and non-printable ... Read More

Mohd Mohtashim
3K+ Views
Assume string variable a holds 'Hello' and variable b holds 'Python', then −Sr.NoOperator & DescriptionExample1+Concatenation - Adds values on either side of the operatora + b will give HelloPython2*Repetition - Creates new strings, concatenating multiple copies of the same stringa*2 will give-HelloHello3[]Slice - Gives the character from the given indexa[1] ... Read More

Mohd Mohtashim
3K+ Views
You can "update" an existing string by (re)assigning a variable to another string. The new value can be related to its previous value or to a completely different string altogether. For example −Example Live Demo#!/usr/bin/python var1 = 'Hello World!' print "Updated String :- ", var1[:6] + 'Python'OutputWhen the above code is ... Read More

Mohd Mohtashim
2K+ Views
Python does not support a character type; these are treated as strings of length one, thus also considered a substring.ExampleTo access substrings, use the square brackets for slicing along with the index or indices to obtain your substring. For example − Live Demo#!/usr/bin/python var1 = 'Hello World!' var2 = "Python Programming" ... Read More

Mohd Mohtashim
522 Views
Random numbers are used for games, simulations, testing, security, and privacy applications. Python includes following functions that are commonly used.Sr.NoFunction & Description1choice(seq)A random item from a list, tuple, or string.2randrange ([start, ] stop [, step])A randomly selected element from range(start, stop, step)3random()A random float r, such that 0 is less ... Read More