Basic python syntax and python syntax

Source: Internet
Author: User

Basic python syntax and python syntax

  • Encoding

By default, python is coded in UTF-8, and all strings are Unicode strings that can define different encodings for the code.

#coding:UTF-8#OR#-*- coding:UTF-8 -*-
  • Python Reserved Words

Reserved Words and keywords, cannot be any identifier name. View All Keywords of the current version: keyword Module

1 import keyword # import keyword module 2 keyword. kwlist
['False', 'none', 'true', 'and', 'as', 'assert ', 'Break', 'class', 'contine ', 'def', 'del ', 'elif', 'else', 'partition t', 'Finally', 'for ', 'from', 'global', 'if ', 'import', 'in', 'is, 'La
  • Note

Single line comment: in the code#The line at the beginning is a comment, and the program will not execute this line during execution

Multi-line comment: "multi-line comment" or '''multi-line comment''

# This is a comment ''', this is the second comment ''' "This is 3rd comments """
  • Data Type

Python has data types: Boolean, integer, long, floating point, String, list, tuples, dictionaries, and dates.

In [4]: bool (True) Out [4]: TrueIn [5]: bool (False) Out [5]: FalseIn [6]: bool (0) out [6]: FalseIn [8]: bool ([]) # Empty list Out [8]: FalseIn [9]: bool (()) # Empty tuples Out [9]: FalseIn [10]: bool ({}) # empty dictionary Out [10]: FalseIn [12]: bool (1) Out [12]: true .................
# Type (): view the data type In [13]: type ("hello world") Out [13]: strIn [14]: type ("123 ") out [14]: str
  • Print () Output

Standard output. print () is a line feed by default. To avoid line feed, add end = ""

>>> Print ("hello world! ", End =" "," hello python! ") # Output without line breaks >>> hello world! Hello python!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.