Posts Tagged ‘Python’

R vs Python

R Programming Language Python Programming Language R favor for Statisticians and Mathematicians Python favor for computer scientists and software engineers R is Statistical tool Python is general purpose language

pip installation problem Cannot fetch index base URL

When tried to install nltk using pip, received following error: C:\Users>pip install nltk Downloading/unpacking nltk Cannot fetch index base URL https://pypi.python.org/simple/ Could not find any downloads that satisfy the requirement nltk Cleaning up… No distributions at all found for nltk Storing debug log for failure in C:\Users\pinnapav\pip\pip.log Solution:Run the command: py -m pip install nltk

How to check list is empty or not in Python

If list contains zero elements or length of list is zero is known as empty list. We can check whether list is empty or not using below methods 1. Declare empty list a=[] #Empty list type(a) 2. Check list is empty or not by using len function of list.

append vs extend in Python

append and extent both are list methods in Python. Following are the definitions of append and extend methods. append extend append is basically used in Python to add one element extend is used to merge two lists or insert multiple elements in one list

How to install pip

What is pip? Pip is recommended tool to install and manage Python packages. Pip installation: 1. Go to site.

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