Python Learning notes-variables and simple data types

Source: Internet
Author: User

1, the name of the variable

Same as C language

2. String

is a series of characters. In Python , a string is enclosed in quotation marks, where the quotation marks can be single or double quotes

2.1 using methods to modify the case of a string

  One of the simplest things you can do with strings is to modify the case of words in them. Take a look at the code below and try to determine its role
(That is, call a statement that resembles a function, in the form of a variable name followed by a dot, plus the name of the method)

" Ada Lovelace " Print (Name.title ())

The last piece of code means to use the title () method to change the first letter of each word of the string stored in the name variable to case.

So the question is, what is the method?

method is What Python can do with data

There are all sorts of ways.

For example, change all to uppercase or lowercase

Name = "Ada Lovelace" Print (Name.upper ()) #全部改为大写print (Name.lower ()) #全部改为小写

 2.3.2 Merging (stitching) strings
You can use the plus sign.

Example:

" Ada "  "Lovelace   " "" + last_name  Print

Both the variable name and the quotation mark can be used in combination

Python can find extra whitespace at the beginning and end of a string. To ensure that there is no whitespace at the end of the string, use Method Rstrip () .

3. Digital

3.1 Integers

Python uses two multiplication sign to represent a exponentiation operation

3.2 Floating point

3.2.1 using function str () to avoid type errors

That is, the C language coercion type conversion, because sometimes the computer does not know that you write the variable is the integer type or as a character.

Usage:

Age ="" "Rd birthday! " Print (message)

3. Introduction to the list A list consists of a series of elements arranged in a particular order. You can create a list of all the letters, numbers 0~9, or names of all family members in the alphabet, or you can add anything to the list, where the elements can have no relationship. Given that a list usually contains multiple elements, it is a good idea to give the list a name that represents a complex number (such as letters , digits, or names ).

in Python , square brackets ([] ) to represent the list, separating the elements with commas. Here is a simple example of a list that contains several bikes:

Bicycles = ['trek''Cannondale'redline ' ' Specialized ' ]print(bicycles)

Python Learning notes-variables and simple data types

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.