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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
abdallah_gamilali_d316a1 profile image
Comment hidden by post author

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

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more