Python Full stack Python Foundation (quad) OP copy

Source: Internet
Author: User
Tags integer division shallow copy

Formatting of strings

Insert the%s into the string as a placeholder, and then define the insert variable.

Arithmetic operations

% modulus to judge odd even

/division has less than sign

The integer division is returned by dividing the integers

Logical operations

and

Or

Not

' Str '. IsDigit () is the ability to determine whether a string can be converted to a number

Boolean operations are false in the following cases!

[] Empty list

{} Empty Dictionary

() empty tuple, empty collection

' Empty string '

0

bitwise OPERATION = = binary operation

The list of copy-shallow copy relationships with deep copy is used in memory placeholder IDs to understand!

Fromkeys () in the dictionary

Create a new dictionary from the sequence key and value set to value.

Describe

The Python Dictionary (Dictionary) Fromkeys () function is used to create a new dictionary, which is the key to the dictionary of elements in the sequence SEQ, and value is the initial value corresponding to all keys in the dictionary.

Grammar

Fromkeys () method syntax:

Dict.fromkeys (seq[, value]))

Parameters

    • SEQ--Dictionary key value list.
    • Value--an optional parameter that sets the values of the key sequence (seq).

return value

The method returns a list.

Instance

The following example shows how the Fromkeys () function is used:

#!/usr/bin/python

Seq = (' name ', ' age ', ' sex ')

Dict = Dict.fromkeys (seq)

Print "New Dictionary:%s"% str (DICT)

Dict = Dict.fromkeys (seq, 10)

Print "New Dictionary:%s"% str (DICT)

The result of the above example output is:

New Dictionary: {' age ': none, ' name ': none, ' Sex ': none}

New Dictionary: {' age ': Ten, ' name ': ten, ' Sex ': 10}

Python Full stack Python Foundation (quad) OP copy

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.