DEV Community

Lakshmi Pritha Nadesan
Lakshmi Pritha Nadesan

Posted on

Day 4 - None Datatype & input() function in Python

None Datatype:

The Python NoneType is a data type that represents the absence of a value. In Python, the NoneType is represented by the keyword "None".

Example:
In this example When you run the code, it will display "hello".

def display():
    print("hello")
display()
Enter fullscreen mode Exit fullscreen mode

Output:

hello
Enter fullscreen mode Exit fullscreen mode

Example 2:

The None is printed because that's the default return value of a function that doesn't have an explicit return statement.

def display():
    print("hello")
print(display())
Enter fullscreen mode Exit fullscreen mode

Output:

hello
None
Enter fullscreen mode Exit fullscreen mode

Example 3:

"hello" is printed by the print() inside the function.
30 is printed by the print() outside the function, which displays the value returned by display().

def display():
    print("hello")
    return 10+20
print(display())

Enter fullscreen mode Exit fullscreen mode

Output:

hello
30
Enter fullscreen mode Exit fullscreen mode

input() function:
The builtin function input() in Python takes input from a user and returns it as a string by default.

Example:

name = input("Enter your name: ")
print("Welcome to Python", name)
print(type(name))

Enter fullscreen mode Exit fullscreen mode

Output:

Enter your name: Pritha
Welcome to Python Pritha
<class 'str'>


Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
abdallah_gamilali_d316a1 profile image
Info Comment hidden by post author - thread only accessible via permalink
Abdallah Gamil ali

data type of input() is a string

Some comments have been hidden by the post's author - find out more