The basic syntax structure of python

content

1.0 Variables

In Python, a variable is created when you assign a value to it: Python has no command for declaring variables. A variable is created the first time a value is assigned to it. (same as matlab)

insert image description here

2.0 Data Types

  • List is an ordered and mutable collection. Duplicate members are allowed.
  • A turtle tuple is an ordered and immutable collection. Duplicate members are allowed.
  • The Set collection is an unordered and unindexed collection. There are no duplicate members.
  • A dict dictionary is an ordered* and mutable collection. There are no duplicate members. As of Python version 3.7, dictionaries are ordered.

insert image description here
insert image description here

3.0 Type Conversion

Conversion in python is done using constructors:

int() - constructs an integer from an integer literal, floating-point literal (by removing all decimals), or string literal (provides a string representing an integer)
float() - constructs a floating-point number from an integer literal, floating-point literal, or string literal (provides Strings represent floats or integers)
str() - Constructs a string from a variety of data types, including strings, integer literals, and floating point literals

insert image description here

4.0 Strings

python string

  • Strings in python are surrounded by single or double quotes. 'hello' is the same as "hello".

insert image description here
Python has no character data type, a single character is just a string of length 1. Square brackets can be used to access elements of a string.

Strings are arrays
insert image description here
insert image description here

  • capitalize() converts the first character to uppercase
  • casefold() converts a string to lowercase
  • center() returns a centered string
  • count() returns the number of times the specified value appears in the string
  • encode() returns the encoded version of the string
  • endswith() returns if the string ends with the specified value
  • truejoin() joins the elements of the iterable to the end of the string
  • find() searches a string for a specified value and returns where it was found
  • format() initializes the specified value in the string
  • index() searches a string for a specified value and returns the position where it was found

Epilogue


"If you are undecided, you can ask the spring breeze, and if the spring breeze does not speak, you will follow your heart" means: if you are hesitant about something, ask the spring breeze how to do it. . "When you are undecided, you can ask the spring breeze, and if the spring breeze does not speak, you will follow your heart." The sentence comes from the "Sword Comes" by the online writer "Fenghuo Opera Princes". The original text is: "If you are undecided, you can ask the spring breeze. Follow your heart".

insert image description here


Guess you like

Origin blog.csdn.net/weixin_46627433/article/details/124285437