Today we share two ways to read Python 3.x files:The first type (low loop): f = open ("file.txt", "R", encoding= "Utf-8")For line in F.readlines ():Print (line)The ReadLines () method loads the contents of the file into memory as a list at a time,
1 "Variables:2 "Conditional judgment and Indentation:Sex = Raw_input ("Please input your gender:") ifSex = ="Girl": Print("I would a little monker with jj!") elifSex = ="Man": Print("Going to homosexual!") Else: Print("You
Python's core--string1. What is a stringIn fact, when it comes to data types, it is the argument with quotation marks, "" Everything inside the quotation marks is a string, and the string is called text.2. Two ways to create a string:3. Method of
Cases:f = open (' a.txt ', encoding= ' utf-8 ')1, F.close ()Closes the file, in order to prevent the open file from always consuming memory.2, F.read ()Read all the contents of the file, the cursor from the beginning position directly to the end of
#-*-Coding:utf-8-*-From sys import ARGVscript, filename = argvPrint "We ' re going to erase%r"% filenamePrint "If you don t want this, hit Ctrl-c (^c)."Print "If You do want this, hit RETURN."Raw_input ("?")Print "Opening the file ..."target = open (
1. Enter a string.
Name=input () or name=input (' please input a string ')
This allows you to receive a string, including spaces, that you can enter. Only the carriage return does not accept, as the Terminator, the second is the
In C/c++/java, Main is the starting point for program execution, and Python also has a similar operating mechanism, but in a different way:Python uses indented alignment to organize code execution, and all non-indented code (not function definitions
1. ClassDescribes a collection of objects that have the same properties and methods.2. Create a classUse class to create a new class, followed by the name of the class and ending with a colon3. Procedures1 #!/usr/bin/python2 #-*-coding:utf-8-*-3 4
Recursive and non-recursive implementation of Fibonacci sequence (Fibonacci)The faipot sequence starts with 0 and 1, and the number is added by the previous two numbers 0, 1, 1, 2, 3, 5, 8,,,,, 144, 233, 377, 610, 987, 1597, 2584,..........Recursive
To create a list:1Name_list = ['python','Java','Shell','C + +']2 #or3Name_list = List (['python','Java','Shell','C + +'])Slices: ( slice: Take multiple elements) 1A = [0,1,2,3,4,5,6]2 Print(A[0])#to access the elements in the list by
1. The function of the automatic task is:Periodically scan the records in the database, and then send the messageThe code is as followsschedulemail.pyImportPymysqlImportSmtplib fromEmail.mime.textImportMimetext fromEmail.headerImportHeaderImport
Study, school general, tutor General, can only rely on their own efforts. It is not too much to have a class. Have a lot of spare time, just can learn something more. Because it is cross-examination, my foundation is really poor, to fill a lot of
Introduction to the functions of XML modulesThis is the main explanation for the etree under the XML module. ElementTree class.1. CreateThe specific code is as followsimport xml.etree.ElementTree as XMnamelist1 = XM.Element("namelist1")#创建标签name1 =
Here's a small piece to bring you a Python django use haystack: full-Text Search framework (example). Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little
Python basics,
print()The function can accept multiple strings separated by commas (,) to form a string of output:
>>> print('The quick brown fox', 'jumps over', 'the lazy dog')The quick brown fox jumps over the lazy dog
Python syntax is
Python functions,
Evaluate the absolute value function abs () function max () can receive any number of parameters and return the largest >>> max (1, 2) 2 >>> max (2, the 3, 1,-5) 3int () function can convert other data types to Integers >>> int ('00
01 Web framework Introduction: 01web framework
I. Nature of Web Framework
All web applications are essentially socket, and your browser is actually a socket Client.
Common web frameworks in python include:
Django
Flask
Web. py
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