What is this python syntax

Python Syntax Data Types

Python offers the following standard data types:


  • as an integer number
  • as a long integer with unlimited (?!) size
  • as a floating point number

All numbers can be combined with each other, with different types it is automatically converted to the more powerful.

int number = 5 long int number = 5L floating point number = 5.0 print 'number:% d, type% s'% (int number, type (int number)) print 'number:% ld, type% s'% (long int number, type (long int number)) print 'Number:% 0.5f, type% s'% (floating point number, type (floating point number)) print

Here character string representations were "woven into" a character string in the form usual with "printf". The object, the text representation of which is to be inserted, follows the character string after a percent sign. If several objects are to be inserted, a tuple (s.d.) must follow the percent sign. All "non-numbers" are noted as strings ("% s").

Text (character string, string)

Texts are not limited in length. Text constants are noted enclosed in single quotation marks or quotation marks. The text ends with the delimiter with which it began.

txt1 = 'A text' txt2 = "Another text" txt3 = 'The character "\ 101" can also be noted as "\ 101" in octal notation' txt4 = "There are the 'usual' substitutes: \ tfor tabulator, for example " print txt1 print txt2 print txt3 print txt4 print

Texts cannot be changed, but you can easily create a modified one from an existing text. For a wide range of other options, see "Sequences".

There is a string module that offers the following services, among others:

  • Lower case and upper case letter conversion
  • Search, replace, disassemble, merge, remove spaces and much more.


There is no special type for truth values ​​in Python! Every object can be seen as a condition; some special objects, namely all that are empty or zero, as well as "none" are considered "false", all others are considered "true".

objects = [0, 1, 0.0, 0.1, 0L, 1L, (), ('a',), [], [0], '', 'Emil', 'None', None, {}, {1 : 'a'}] for o in objects: print 'The object', o, 'of type', type (o), 'is', if o: print 'true' else: print 'false'

The result of a comparison is 0 or 1.

Self-defined data types (such as ADT = Abstract Data Type, as offered in some languages)

there is not any; however, classes can be used to achieve the desired effect.