Posts Tagged ‘Python’

Add new keys to dictionary in Python

We can add an item to existing dictionary in Python using following methods. Method1: Using update method of dictionary: 1. Create dictionary: >>> countries={‘United States of America’:’Washington’,’Canada’:’Ottawa’,’India’:’New Delhi’} >>> countries {‘United States of America’: ‘Washington’, ‘Canada’: ‘Ottawa’, ‘India’: ‘New Delhi’}

Difference between Lists and Tuples in Python

List Tuple List objects are mutable objects. Which means can be changed after its created Tuple objects are immutable objects. Which means can’t be changed after its created Lists have order Tuple has structure Iterating the list is slower Iterating the tuple is faster List objects are not used as keys for the dictionary Tuple […]

NameError: name ‘raw_input’ is not defined

Traceback (most recent call last): File “<pyshell#0>”, line 1, in first_name=raw_input() NameError: name ‘raw_input’ is not defined   Reason:

Difference between scripting language and programming language

Following are major difference between scripting language and programming language: Scripting Language: Runs in response to an event Performs instructions from top to bottom Little or no user interaction. Example: Powershell, PHP, Perl

Fibonacci Sequence in Python

What is Fibonacci Sequence? Depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two. Fibonacci Sequence: 0,1,1,2,3,5,8,13,21,34,55,89,144,233, … 1,1,2,3,5,8,13,21,34,55,89,144,233, … Fibonacci Sequence Formula:

Powered by k2schools