Python Programming/Strings Tutorial

String There are three ways you can declare a string in Python: single quotes (‘), double quotes (“), and triple quotes (“””). You can use quotation marks within strings by placing a backslash directly before them, so that Python knows you want to include the quotation marks in the string, instead of ending the string there. Placing a backslash directly…

Continue Reading →

Errors and Exceptions in python

Catching exceptions Whenever a runtime error occurs, it creates an exception object. The program stops running at this point and Python prints out the traceback, which ends with a message describing the exception that occurred. Ex→ dividing by zero creates an exception: >>> print(55 / 0) Traceback (most recent call last): File “<pyshell#0>”, line 1, in <module> print(55 / 0)…

Continue Reading →

Working with files in Python

Files Note: Take care of Indentation in codes. While a program is running, its data is stored in random access memory (RAM). RAM is fast and inexpensive, but it is also volatile, which means that when the program ends, or the computer shuts down, data in RAM disappears. To make data available the next time the computer is turned on…

Continue Reading →

Introduction to NumPy

Numpy NumPy is the fundamental package for scientific computing with Python. It contains among other things: a powerful N-dimensional array object sophisticated (broadcasting) functions tools for integrating C/C++ and Fortran code useful linear algebra, Fourier transform, and random number capabilities Why NumPy? The standard Python data types are not very suited for mathematical operations. EX-→ Suppose we have a list.…

Continue Reading →

How to counts the number of decimal digits in a positive integer in Python

The following snippet counts the number of decimal digits in a positive integer: n = 40265 count = 0 while n != 0: count = count + 1 n = n // 10 print(count) This snippet demonstrates an important pattern of computation called a counter. The variable count is initialized to 0 and then incremented each time the loop body…

Continue Reading →

Creating an administration site for your models in Django

Django comes with a built-in administration interface that is very useful for editing content. The Django admin site is built dynamically by reading your model metadata and providing a production-ready interface for editing content. You can use it out-of-the-box, configuring how you want your models to be displayed in it. Remember that django.contrib.admin is already included in the INSTALLED_APPS setting…

Continue Reading →

Creating an application in Django

Let’s create your first Django application. I am going to show you how to create a blog App. From your project’s root directory, run the following command: python3 manage.py startapp blog admin.py : This is where you register models to include them into the Django administration site. Using the Django admin site is optional. migrations : This directory will contain…

Continue Reading →

Know about default Django Project settings

  Let’s open the settings.py file and take a look at the configuration of our project.     DEBUG is a boolean that turns on/off the debug mode of the project. If set to True , Django will display detailed error pages when an uncaught exception is thrown by your application. When you move to a production environment, remember you…

Continue Reading →

Installing Django and creating your first project

  If you have already installed Django, you can skip and jump directly to Creating your first project. If you haven’t installed Django yet, here is a quick guide to installing Django for local development. Django works well with Python versions 2.7 or 3.If you are not sure if Python is installed in your computer, you can verify it by…

Continue Reading →

Introduction to python IDLE

Before you Write and run Python code, you need to make sure the Python interpreter is on your computer. Let’s check your computer for Python 3. Open up a command-line prompt: If you are using Mac OS X or Linux, Type: python3 -V (That’s an UPPERCASE “V”) On windows , Type: c:\Python31\Python.exe -V Without the UPPERCASE “v” you are taken…

Continue Reading →