EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Python 3 Tutorial Python 3 Commands
Secondary Sidebar
Python 3 Tutorial
  • Python 3 Tutorial
    • Python 3 Commands
    • Python 3 Array
    • Python 3 Operators
    • Python 3 NumPy
    • Python 3 Webserver
    • Python 3 yield
    • Python 3 Pip
    • Python 3 Install
    • Python 3 raw_input
    • Python 3 HTTP Server
    • Python 3 Threading
    • Python 3 Requests
    • Python 3 Module Index
    • Python 3 String Format
    • Python 3 Unicode
    • Python 3 GUI
    • Python 3 xrange
    • Python 3 Tuple
    • Python 3 input
    • Python 3 JSON
    • Python 3 string
    • Python 3 try-except
    • Python 3 RegEx
    • Python 3 Object-Oriented Programming
    • Python 3 zip
    • Python 3 Exception
    • Python 3 write to file
    • Python 3 Functions
    • Python 3 List Function
    • Python 3 While Loop
    • Python 3 Global Variable
    • Python 3 String Methods
    • Python 3 interpreter
    • Python 3 REPL
    • Python 3 else if
    • Python 3 basics
    • Python 3 cheat sheet
    • Python 3 Print
    • Python 3 For Loop
    • Python 3 range
    • Python 3 Dictionary
    • Python 3 has_key
    • Python 3 URLlib

Python 3 Commands

By Priya PedamkarPriya Pedamkar

Python 3 Commands

Introduction to Python 3 Commands

Python 3 commands have been introduced with Python 2 features, and it is compatible with python 2 with the help of using some inbuilt keywords to support the functionalities. Python 3 command was released in the year 2008. Python 3 is more intuitive to programmers and more precise while providing the result. Syntax has been changed for python 3 to get more clarity on what is written and what should be the output.

Basic Python 3 Commands

Basic Commands are as follows:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,268 ratings)

1. Print function

In Python 3, the print function is used with parenthesis to show the output, which is not available in python 2.

Syntax:

print ("Content to display")

Example:

print ("Hello World")

2. Input function

In this Python 3 command, the entered data is always treated as a string even if the data is inserted without ‘ ‘.

Syntax/ example:

>>>X: input("x:")
		X: 5
		>>>X
		'5'

3. Integer division

In Python 3, the division is more precise than python 2 and gives a better result.

Syntax/ example:

X:3/2

1.5 #by default, it will give this number which is not available for Python 2

4. range function

In Python 3, the Xrange function of python 2 has been renamed as a range function in python 3

Syntax/ example:

range ()

5. raise function

In Python 3, an exception argument has to be put in parenthesis.

Syntax/ example:

raise an exception ("There is some issue")

6. Arguments

In python 3 commands, arguments need to be declared with the help of the keyword ‘as’

Syntax/ example:

except issue an error

7. Next function

In python 3, the next function is being used, and the .net function cannot be used as it throws an error named as attribute error.

Syntax/ example:

next (abc)

8. Unicode

In python 3, strings are mainly stored as Unicode, that is, utf-8 strings and having byte classes as bytes and byte array.

9. Decision statement

If else statement is being used for decision making in python 3.

Syntax/ example:

var=10
if (var==10) : 
    print ("Value is 10")
print ("Ok")

10. Strings

In python 3, square brackets along with index are using to get the substring.

Syntax/ example:

var = "Hello World"
print ("var[0]: ", var [0]) #result would be 'H' 

Intermediate Python 3 Commands

Intermediate Commands of Python 3 are as follows:

1. For loop

In Python 3, for loop is being used to execute the statement multiple times.

Syntax/ example:

list= [1,2,3]
for x in list:
	print (x, end = "")

2. While loop,

it will repeat the statement while the condition is true.

Syntax/ example:

while true:
	try:
	    print ("next value")
	except stopvalue:
	    Sys.exit()

3. Math functions

There are many math functions that can be used in Python 3 to get the values or results.

Syntax/ example:

cmp(x,y)

4. List values

In Python 3, the values can be listed in list form and access the result.

Syntax/ example:

list=['TOM', 'JOHN', 'Latham', 'Mary' ]
print ("list[0]:", list[0])

The output would be –‘TOM.’

5. Functions

In Python 3, the function would be defined with the keyword def

Syntax/ example:

def abc( str ):
	"Hello world, my first function"
	print (str)
	return

6. Dictionary

In Python 3, it is used to assign the value and update the value as well.

Synatx/ example:

dict = {'Name': 'Tom', 'Salary': 7500, 'Location': 'USA'}
print ("dict['Name']: ", dict['Name'])# output would be: Tom
dict['Salary'] = 8500#updating the existing value.
print ("dict['Salary']: ", dict['Salary']) #Output would be 8500

7. Sending email

In python 3, the smtp library object is being used for sending an email.

Syntax/ example:

import smtplib
Smtpobj = smtplib.SMTP([host [, port [, local_hostname]]])

8. Threading

In python 3, threading is used for various reasons and different threading method has been used like threading.activecount(), threading.currentthread(), threading.enumerate().

9. Regular expression

It is being used for matching the string from the number of strings. In this one of the example is the use of the match function.

Syntax/ example:

reg.match(pattern, string, flags = 0)

10. Database connectivity

In python 3, MySql is mainly used as a database, and PyMySQL is an interface connecting to the MySQL database.

Syntax/ example:

import PyMySQL
db = PyMySQL.connect ("localhost", "username", "Password", "Database name")

Tips and Tricks to Use Python 3 Commands

  • Use conditional operators wisely
  • Use feature detection instead of using version detection
  • Prevent compatibility regressions
  • Check the dependencies while transitioning of the application to Python 3
  • Use continuous integration to stay stable
  • Use optional static type checking
  • Update setup.py file to denote python 3 compatibility
  • Use dictionary, list where ever needed
  • Debug the scripts to check where is an error or issue.
  • Use enums
  • Use python functions to get the result faster
  • Always check the memory usage of objects

Conclusion

Python 3 makes life comfortable for the programmers by introducing new features and compatibility to older versions as well. With the help of compatibility, the old applications can be easily moved in the python 3 environment and make it up and running. Python 3 functions and its dynamic typing are really useful for the programming and make the application’s performance better.

Recommended Articles

This has been a guide to Python 3 Commands. Here we have discussed basic as well as advanced Python 3 Commands and some immediate Python 3 Commands. You may also look at the following article to learn more –

  1. Tableau Commands
  2. HBase Commands
  3. MongoDB Commands
  4. Pig Commands
Popular Course in this category
Python Certifications Training Program (40 Courses, 13+ Projects)
  40 Online Courses |  13 Hands-on Projects |  215+ Hours |  Verifiable Certificate of Completion
4.8
Price

View Course
6 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more