随笔分类 - Python
摘要:List comprehensions provide a concise way to create new lists, where each item is the result of an operation applied to each member of an existing lis
阅读全文
摘要:isinstance("foo", str) isinstance(1, int) isinstance(4.0, float)
阅读全文
摘要:For example you want to know what methods are available in Python for String, you can do : Output: Now for example, we want to see How to use 'swapcas
阅读全文
摘要:Single quotes and double quotes can both be used to declare strings in Python. You can even use triple-double quotes! Learn when to use each in this l
阅读全文
摘要:Python scripts can be executed by passing the script name to the python command or created as executable commands that can run stand-alone. You’ll lea
阅读全文
摘要:In this lesson, you will learn what mutable and immutable objects are, and the difference between them. This understanding will help you determine whe
阅读全文
摘要:If you’ve used other programming languages, you may have learned that an empty object is not the same as an object that does not exist. In this lesson
阅读全文
摘要:Virtual Environments ensure that dependencies from one Python application don’t overwrite the dependencies of another application. In this lesson, you
阅读全文
摘要:import time import urllib import bs4 import requests start_url = "https://en.wikipedia.org/wiki/Special:Random" target_url = "https://en.wikipedia.org/wiki/Philosophy" def find_first_link(url): ...
阅读全文
摘要:# Python's list slice syntax can be used without indices # for a few fun and useful things: # You can clear all elements from a list: >>> lst = [1, 2, 3, 4, 5] >>> del lst[:] >>> lst [] # You can r...
阅读全文
摘要:https://docs.python.org/2/library/collections.html
阅读全文
摘要:>>> import itertools >>> for p in itertools.permutations('ABCD'): ... print(p) ('A', 'B', 'C', 'D') ('A', 'B', 'D', 'C') ('A', 'C', 'B', 'D') ('A', 'C', 'D
阅读全文
摘要:The Python Standard Library has a lot of modules! To help you get familiar with what's available, here are a selection of our favourite Python Standar
阅读全文
摘要:Python allows you to open a file, do operations on it, and automatically close it afterwards using with. In the example above we open a file, perform
阅读全文
摘要:Default arguments are a helpful feature, but there is one situation where they can be surprisingly unhelpful. Using a mutable type (like a list or dic
阅读全文
摘要:Python provides another useful built-in type: tuples. Tuples are used to store related pieces of information. Consider this example involving latitude
阅读全文
摘要:Write a function, remove_duplicates that takes a list as its argument and returns a new list containing the unique elements of the original list. The
阅读全文
摘要:Let's introduce a new string method, join: Also note thatjoin will trigger an error if we try to join anything other than strings. For example:
阅读全文
摘要:In addition to accessing individual elements from a list we can use Python's slicing notation to access a subsequence of a list. Consider this list of
阅读全文
摘要:One particularly useful string method is format. The format method is used to construct strings by inserting values into template strings. Consider th
阅读全文