Python Learning notes (0)

Source: Internet
Author: User
Tags first string

What type of language is Python?

Python is a scripting language

Python:https://www.python.org/downloads/

Python version: Python 3.4.2-64bit

The scripting language (Scripting language) is a computer programming language and therefore allows developers to write programs that give computers orders to act. Getting things done quickly and easily in a simple way is often an important principle in creating scripting languages, and based on this principle, scripting languages are often easier to use than system programming languages such as C, C + +, or Java.
Also let the scripting language have some features that are part of the scripting language:

  • Syntax and structure are usually relatively simple
  • Learning and using is usually relatively simple
  • Usually it is easy to modify the "interpretation" of the program as a way of running, without the need to "compile"
  • Program development capacity is better than running performance

    A script can automate the interaction that would otherwise be done with the keyboard. A shell script consists primarily of commands that would otherwise need to be entered at the command line, or in a text editor where users can use scripts to combine common operations into a set of serial. The language used primarily to write this script is called a scripting language. Many scripting languages have actually exceeded simple user command serial instructions and can also write more complex programs.

    What is IDLE?

    Idle is a python shell,shell means "shell", basically, is a way to interact with the program by typing text! Like our Windows cmd window, a black command window like Linux, they're all shells, and using them, we can give commands to the operating system. Similarly, we can use the idle shell to interact with Python. Once you've installed Python, searching directly for idle is displayed.

    Open idle and see ">>>" This prompt, "it" means to tell us that Python is ready, waiting to type Python instructions.

    We can try typing the instructions:

    >>> print ("I love Python")

    As you can see, Python's Idle directly prints the string I love Python

    You can try typing the wrong command:

    >>> System.out.println ("I love Python"); Traceback (most recent):  File "<pyshell#1>", line 1, in <module>    System.out.println ("I Love Python ") Nameerror:name ' System ' was not defined

    found that the idle directly to our error, and very friendly to remind us that Nameerror:name ' System ' is not defined,system this thing does not define

    Try typing the Python2 syntax:

    >>> print "I love Python" syntaxerror:missing parentheses on call to ' print '

    It will tell us that it is a wrong syntax.

    Typing a lot of wrong information, try typing the correct information, such as calculation:

    >>> Print (5 + 8) 13

    In idle, the print calculation can even be printed without the print () function, which can be directly entered into a numeric calculation, such as:

    # Add >>> 5 + 813# subtract, and output negative >>> 5-8-3# subtract, output is positive >>> 9-54# multiply >>> 2 * 36# divide, output is a small floating point type Number >>> 9/33.0# If you want to output an integer, use two division sign "//" >>> 9//33

    Not only can it be used as a calculator, but it can also handle very large numerical computations:

    >>> 1234567890123456789 * 987654321098765432112193263113702179522374638011112635269

    It can also be used to add strings:

    # Add string >>> ' I ' + ' love ' + ' Python ' ' Ilovepython ' # string added is too ugly, we add a space after the word >>> ' i ' + ' + ' love ' + ' + ' P Ython ' + '! ' I Love python! ' # Add Chinese and English >>> "I" + "Love" + "Python" ' I love python '

    Python is not just a concatenation and addition of strings, it can also be multiplied with strings:

    >>> ' I Love python! ' * 3 ' I love python! I Love python! I Love python! ‘

    Of course, not all strings can be multiplied, such as the string multiplied by the string, will be error, Python is not so only, the string division, subtraction will be error:

    # string and number added, error >>> ' I love Python ' + 5Traceback (most recent call last):  File "<pyshell#7>", Line 1, in & Lt;module>    ' I love Python ' + 5typeerror:can ' t convert ' int ' object to str implicitly# string multiplied by string, error >>> ' I Love python! ' * ' Love ' Traceback (most recent):  File "<pyshell#40>", line 1, in <module>    ' I l Ove python! ' * ' love ' typeerror:can ' t multiply sequence by non-int of type ' str ' # string subtraction, error >>> ' I love python! '- ' Love ' Traceback (more recent call last):  File "<pyshell#41>", line 1, in <module>    ' I love python! '-' Love ' typeerror:unsupported operand type (s) for-: ' str ' and ' str ' # Divide the string, error >>> ' I love python! '/3Traceback (mo St recent Call last):  File "<pyshell#42>", line 1, in <module>    ' I love python! '/3typeerror:unsuppor Ted operand type (s) for/: ' str ' and ' int '

    Why >>>print (' I love fishc.com ' * 5) can execute normally, but >>>print (' I love fishc.com ' + 5) error?

    In Python it is not possible to add two completely different things, such as numbers and text, for this reason that >>>print (' I love Python ' + 5) will not be able to make an error. It's like saying, "Cang jing empty plus 5, what's it going to be?" "It doesn't make much sense!" But multiplying by an integer doubles it to a certain extent, and the front example is to print the string "I love Python" five times.

    What is the role of print ()?

    Having said so much, I forgot print (), so what is print ()?

    Print () displays some text in the Output window. We can enter help (print) in the idle to ask for assistance

    One of the more useful is the built-in method for print Sep and end

    Sep---Inserts a value between strings, by default a space, such as:

    # print, each string is separated by a "," comma, the default is a space >>> print (' I am the first string ', ' I am the second string ') I was the first string I was the second string # If I wanted to make two strings without a space, You can use Sep >>> print (' I'm the first string ', ' I'm the second string ', sep= ') I'm the first string I'm the second string # Of course, you can also use other text to separate strings. >>> print (' I am the first string ', ' I am the second string ', sep= '---my existence, just to separate you---') I am the first string---I exist to separate you---I am the second string # Use commas to separate the strings, in order to effect obvious, the estimated extra a lot of comma ~>>> print (' I ', ' love ', ' Python ', sep= ',,,,, ') I,,,,, love,,,,, python# \ n is a newline character > >> print (' I'm the first string ', ' I'm the second string ', sep= ' \ n ') I'm the first string I'm the second string

    The end---Appends a value to the end of the string, by default a newline, such as:

    # in the idle, input print Click Enter, directly output, if using a semicolon, you can write on a line of two instructions in the output, Python idle is not very convenient ~>>> print (' I in the first line! ');p rint (' I'm on the second line! ' I'm on the first line! I'm on the second line! # If you don't add end, the last value is \ n, but if you add end= ', you get rid of it and turn it into an empty string, so two print can show ~>>> print on one line (' I'm on the first line! ', end= ');p rint (' I'm on the second line! ' I'm on the first line! I'm on the second line! >>> print (' I'm on the first line! ', end= '---just don't let the line break---');p rint (' I'm on the second line! ' I'm on the first line! ---just don't let the line break---me in the second line!

    If I need to embed a double quote in a string, I can do this:

    My name ' s Python

    What is the difference between input >>> ' python ' and input >>>print (' Python ')?

    The direct input is to print the result and type to the screen, while print prints the results to the screen, try it yourself and observe the results!

    # output is quoted >>> ' python ' python ' # output without quotes >>> print (' python ') python

    If you are in a text editor, the problem is obvious. For example, in idle, use "Ctrl + N" To open a text editor

    print ' Python ' directly, click F5 to run and find nothing in idle

    with print (), it can be printed.

    Setting environment variables

    Set the environment variables for your operating system so that you can easily enter the Python environment

    System variables, environment variables, advanced system settings, properties, anti-key computer, and so on. Add a Python installation directory to the variable value, edit

    Set it up, type cmd in the run, enter Python, and you can test it. After executing python, it's like idle. It's just a dark window.

    Why should we use Python3?

    Why should we use Python? What the hell is wrong with Python2? It seems that many programmers are still using Python2?

    Indeed, there are quite a few programmers using Python2, but Python3 is the future of Python, just like XP and WIN7. In fact, Python3 in the new features is really wonderful, it is worth to study deeply! Feel that if you understand the Python3,python2 code reading is not a problem for you!

Python Learning notes (0)

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.