python string numerical calculation

  • 2020-05-12 02:50:37
  • OfStack

Python is an object-oriented language, but it does not encapsulate the standard classes into the library like C++1, instead, it is further encapsulated. The language itself integrates some classes and functions, such as print, list, dict etc, which brings great convenience to programming

Python USES # for single-line comments and "" or" "for multi-line comments

Numerical calculation


>>> print "One hour has", 60 * 60 , "seconds" 
One hour has 3600 seconds
>>> result = 12 #  with 1 Lines of code are segmented with Spaces to make the format clearer 
>>> print result
12


string

In Python you use "" or "" to represent a string, and it is customary to use "" for a single word and "" for a sentence.


>>> print 'Here is Python'
Here is Python
>>> print "Here is Python,too"
Here is Python,too

If you use non-ASCII encoded characters in the text, you can add # -* -coding: utf-8 -*- to the opening of the python script


Related articles: