Sunday, April 30, 2023

PYTHON(DAY4) Input and Output Funcions

PYTHON(DAY4)

Input and Output in python

INPUT FUNCTION

How to Take Input from User in Python

Syntax:

input('xyz')

where xyz is an optional string that is displayed on the string at the time of taking input.

Example 1: Getting input from user

x = input('Enter your Name:')
print(x)

here, we get the output as:

Enter your Name: xyz

type() function:

Example 2: using type function

y = 'hi'
print(type(y))

here, we get the output as:

<class ‘str’>

Python takes all the input as a string input by default. To convert it to any other data type we have to convert the input explicitly. For example, to convert the input to int or float we have to use the int() and float() method respectively.

How to take integer as an input

Example 3: using int() function

x = int(input('enter a number:'))
print(x)

here, we get the output as:

enter a number: 10

How to take Multiple Inputs from user

  • Using split() method

Syntax:

input().split(separator, maxsplit)

Parameters

The separator parameter breaks the input by the specified separator. By default, whitespace is the specified separator.

The split() method is used to split the Python string, but we can use it to get the multiple values too.

a,b,c = input('enter three values:')
print('enter first name:',a)
print('enter last name:',b)
print('enter school name:',c)

here, we get output as:

enter three values: raj kumar nirmal
enter first name: raj
enter last name: kumar
enter school name: nirmal

OUTPUT FUNCTION

Example:

print('hi')
print('hello')

here, we get output as:

hi
hello

what if we use “end” parameter in print statement, let see the difference between the above print statement and this statement

By default end takes space to print the outputs in single statement seperated by space

print('hello', end = ' ')
print('world)

here, we get output as:

hello world

Saturday, April 29, 2023

PYTHON(DAY 3) KeyWords

 PYTHON(DAY 3)

Today, we are going to learn about keywords in python.

KeyWords in python

Python’s built-in methods and classes are not the same as the keywords. Built-in methods and classes are constantly present; however, they are not as limited in their application as keywords.

Assigning a particular meaning to Python keywords means you can’t use them for other purposes in our code. You’ll get a message of SyntaxError if you attempt to do the same.

Python contains thirty-three keywords

keywords in python
import keyword
print("The set of keywords in this version is: ")
print( keyword.kwlist )

By using, this kwlist we can display the list of keywords in python

Friday, April 28, 2023

PYTHON(DAY 2) variables and literals

 PYTHON(DAY 2)

variables and literals

Variable is a name that is used to refer to memory location. Python variable is also known as an identifier and used to hold value.

In Python, we don’t need to specify the type of variable because it is smart enough to get variable type.

Python variables are more like pointers that point to memory location of our literals.

There are few rules and regulations to name a variable, these rules are naming conventions of a variable

  1. Name should start with an alphabet or an underscore(_).

EX: abc, _xyz, a_b_c

2. Variable name should not start with a digit or with any other special symbol.

EX: $abc, 123abc

3. Variable name should not contain spaces.

EX: a bc, 1 23

4. we should not use a variable that changes color after giving a space, because those may be keywords or words that have special meaning or task assigned to them.

EX: print, return… etc

Variable Declaration:

x = 5;
print(x)

Here, “x” is a variable that points to the memory location where the value is stored

variables

Comments in python

In python there are 2 types of comments

1) single line comments

2) Multi line comments

>> Single line comments are used by using hash infront of the text or code and it does not execute when we run a program

EX:

# line 1
# line 2
# a = b+c

>> Multi line comments are used for documentation purpose like doc strings

>> multi line comments are enclosed within triple single quotes (or) triple double quotes

>> these comments executes at the time of execution

EX:

''' line1
line2
line3 '''

Thursday, April 27, 2023

BASICS OF PYTHON

PYTHON FOR BEGINNERS

#Basics | Glance of python

WHAT IS PYTHON?

Python is a very popular general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1981.

BASIC SYNTAX OF PYTHON:

There is no use of curly braces or semicolon in Python programming language. It is English-like language. But Python uses the indentation to define a block of code. Indentation is nothing but adding whitespace before the statement when it is needed. For example -

def func():
statement 1
statement 2
…………………
…………………
statement N

APPLICATIONS OF PYTHON:

Web Applications

Desktop GUI Applications

Software Development

Business Applications

Image Processing Applications…ect

Applications of python

WHY TO LEARN PYTHON?

Python is fairly easy to learn, so if you are starting to learn any programming language then Python could be your great choice. There are many other good reasons which makes Python as the top choice of any programmer:

  • Python is Open Source which means its available free of cost.
  • Python is simple and so easy to learn
  • Python is versatile and can be used to create many different things.
  • Python has powerful development libraries include AI, ML etc.
  • Python is much in demand and ensures high salary

FEATURES OF PYTHON:

Python provides many useful features which make it popular and valuable from the other programming languages. It supports object-oriented programming, procedural programming approaches and provides dynamic memory allocation. We have listed below a few essential features.

1) Easy to Learn and Use

Python is easy to learn as compared to other programming languages. Its syntax is straightforward and much the same as the English language. There is no use of the semicolon or curly-bracket, the indentation defines the code block. It is the recommended programming language for beginners.

2) Expressive Language

Python can perform complex tasks using a few lines of code. A simple example, the hello world program you simply type print(“Hello World”). It will take only one line to execute, while Java or C takes multiple lines.

3) Interpreted Language

Python is an interpreted language; it means the Python program is executed one line at a time. The advantage of being interpreted language, it makes debugging easy and portable.

4) Cross-platform Language

Python can run equally on different platforms such as Windows, Linux, UNIX, and Macintosh, etc. So, we can say that Python is a portable language. It enables programmers to develop the software for several competing platforms by writing a program only once.

5) Free and Open Source

Python is freely available for everyone.It has a large community across the world that is dedicatedly working towards make new python modules and functions. Anyone can contribute to the Python community. The open-source means, “Anyone can download its source code without paying any penny.”

6) Object-Oriented Language

Python supports object-oriented language and concepts of classes and objects come into existence. It supports inheritance, polymorphism, and encapsulation, etc. The object-oriented procedure helps to programmer to write reusable code and develop applications in less code.

7) Extensible

It implies that other languages such as C/C++ can be used to compile the code and thus it can be used further in our Python code. It converts the program into byte code, and any platform can use that byte code.

8) Large Standard Library

It provides a vast range of libraries for the various fields such as machine learning, web developer, and also for the scripting. There are various machine learning libraries, such as Tensor flow, Pandas, Numpy, Keras, and Pytorch, etc. Django, flask, pyramids are the popular framework for Python web development.

9) GUI Programming Support

Graphical User Interface is used for the developing Desktop application. PyQT5, Tkinter, Kivy are the libraries which are used for developing the web application.

10) Integrated

It can be easily integrated with languages like C, C++, and JAVA, etc. Python runs code line by line like C,C++ Java. It makes easy to debug the code.


Building Static Website(part6) HTML Lists

  Building Static Website (part6) HTML Lists Today, let us add some lists to our detailed view section by using html lists. Lists: List is a...