Python学习

使用Python学习AI的学习攻略 基于python语言的AI学习思路参考 阅读详情

From

http://www.hetland.org/python/instant-hacking.php

Instant Hacking

[If you like this tutorial, please check out my book Practical Python.]

This is a short introduction to the art of programming, with examples written in the programming language Python. (If you already know how to program, but want a short intro to Python, you may want to check out my article Instant Python.) This article has been translated into Italian, Polish, Japanese, Serbian , and Brazilian Portuguese, and is in the process of being translated into Korean.

This page is not about breaking into other people's computer systems etc. I'm not into that sort of thing, so please don't email me about it.

Note: To get the examples working properly, write the programs in a text file and then run that with the interpreter; do not try to run them directly in the interactive interpreter - not all of them will work. (Please don't ask me on details on this. Check the documentation or send an email to help@python.org).

The Environment

To program in Python, you must have an interpreter installed. It exists for most platforms (including Macintosh, Unix and Windows). More information about this can be found on the Python web site. You also should have a text editor (like emacs, notepad or something similar).

What is Programming?

Programming a computer means giving it a set of instructions telling it what to do. A computer program in many ways resembles recipes, like the ones we use for cooking. For example [1]:

    Fiesta SPAM Salad

    Ingredients:

    Marinade:
    1/4 cup lime juice
    1/4 cup low-sodium soy sauce
    1/4 cup water
    1 tablespoon vegetable oil
    3/4 teaspoon cumin
    1/2 teaspoon oregano
    1/4 teaspoon hot pepper sauce
    2 cloves garlic, minced

    Salad:
    1 (12-ounce) can SPAM Less Sodium luncheon meat,
        cut into strips
    1 onion, sliced
    1 bell pepper, cut in strips
    Lettuce
    12 cherry tomatoes, halved

    Instructions:

    In jar with tight-fitting lid, combine all marinade ingredients;
    shake well. Place SPAM strips in plastic bag. Pour marinade
    over SPAM. Seal bag; marinate 30 minutes in refrigerator.
    Remove SPAM from bag; reserve 2 tablespoons marinade. Heat
    reserved marinade in large skillet. Add SPAM, onion, and
    green pepper. Cook 3 to 4 minutes or until SPAM is heated.
    Line 4 individual salad plates with lettuce. Spoon hot salad
    mixture over lettuce. Garnish with tomato halves. Serves 4.

Of course, no computer would understand this... And most computers wouldn't be able to make a salad even if they did understand the recipe. So what do we have to do to make this more computer-friendly? Well – basically two things. We have to (1) talk in a way that the computer can understand, and (2) talk about things that it can do something with.

The first point means that we have to use a language – a programming language that we have an interpreter program for, and the second point means that we can't expect the computer to make a salad – but we can expect it to add numbers, write things to the screen etc.

Hello...

There's a tradition in programming tutorials to always begin with a program that prints "Hello, world!" to the screen. In Python, this is quite simple:

    print "Hello, world!"

This is basically like the recipe above (although it is much shorter!). It tells the computer what to do: To print "Hello, world!". Piece of cake. What if we would want it to do more stuff?

    print "Hello, world!"
    print "Goodbye, world!"

Not much harder, was it? And not really very interesting... We want to be able to do something with the ingredients, just like in the spam salad. Well – what ingredients do we have? For one thing, we have strings of text, like "Hello, world!", but we also have numbers. Say we wanted the computer to calculate the area of a rectangle for us. Then we could give it the following little recipe:

    # The Area of a Rectangle

    # Ingredients:

    width = 20
    height = 30

    # Instructions:

    area = width*height
    print area

You can probably see the similarity (albeit slight) to the spam salad recipe. But how does it work? First of all, the lines beginning with # are called comments and are actually ignored by the computer. However, inserting small explanations like this can be important in making your programs more readable to humans.

Now, the lines that look like foo = bar are called assignments. In the case of width = 20 we tell the computer that the width should be 20 from this point on. What does it mean that "the width is 20"? It means that a variable by the name "width" is created (or if it already exists, it is reused) and given the value 20. So, when we use the variable later, the computer knows its value. Thus,

    width*height

is essentially the same as

    20*30

which is calculated to be 600, which is then assigned to the variable by the name "area". The final statement of the program prints out the value of the variable "area", so what you see when you run this program is simply

    600

Note: In some languages you have to tell the computer which variables you need at the beginning of the program (like the ingredients of the salad) – Python is smart enough to figure this out as it goes along.

Feedback

OK. Now you can perform simple, and even quite advanced calculations. For instance, you might want to make a program to calculate the area of a circle instead of a rectangle:

    radius = 30

    print radius*radius*3.14

However, this is not significantly more interesting than the rectangle program. At least not in my opinion. It is somewhat inflexible. What if the circle we were looking at had a radius of 31? How would the computer know? It's a bit like the part of the salad recipe that says: "Cook 3 to 4 minutes or until SPAM is heated." To know when it is cooked, we have to check. We need feedback, or input. How does the computer know the radius of our circle? It too needs input... What we can do is to tell it to check the radius:

    radius = input("What is the radius?")

    print radius*radius*3.14

Now things are getting snazzy... input is something called a function. (You'll learn to create your own in a while. input is a function that is built into the Python language.) Simply writing

    input

won't do much... You have to put a pair of parantheses at the end of it. So input() would work – it would simply wait for the user to enter the radius. The version above is perhaps a bit more user-friendly, though, since it prints out a question first. When we put something like the question-string "What is the radius?" between the parentheses of a function call it is called passing a parameter to the function. The thing (or things) in the parentheses is (or are) the parameter(s). In this case we pass a question as a parameter so that input knows what to print out before getting the answer from the user.

But how does the answer get to the radius variable? The function input, when called, returns a value (like many other functions). You don't have to use this value, but in our case, we want to. So, the following two statements have very different meanings:

    foo = input

    bar = input()

foo now contains the input function itself (so it can actually be used like foo("What is your age?"); this is called a dynamic function call) while bar contains whatever is typed in by the user.

Flow

Now we can write programs that perform simple actions (arithmetic and printing) and that can receive input from the user. This is useful, but we are still limited to so-called sequential execution of the commands, that is – they have to be executed in a fixed order. Most of the spam salad recipe is sequential or linear like that. But what if we wanted to tell the computer how to check on the cooked spam? If it is heated, then it should be removed from the oven – otherwise, it should be cooked for another minute or so. How do we express that?

What we want to do, is to control the flow of the program. It can go in two directions – either take out the spam, or leave it in the oven. We can choose, and the condition is whether or not it is properly heated. This is called conditional execution. We can do it like this:

    temperature = input("What is the temperature of the spam?")

    if temperature > 50:
        print "The salad is properly cooked."
    else:
        print "Cook the salad some more."

The meaning of this should be obvious: If the temperature is higher than 50 (centigrades), then print out a message telling the user that it is properly cooked, otherwise, tell the user to cook the salad some more.

Note: The indentation is important in Python. Blocks in conditional execution (and loops and function definitions – see below) must be indented (and indented by the same amount of whitespace; a <tab> counts as 8 spaces) so that the interpreter can tell where they begin and end. It also makes the program more readable to humans.

Let's return to our area calculations. Can you see what this program does?

    # Area calculation program

    print "Welcome to the Area calculation program"
    print "---------------------------------------"
    print

    # Print out the menu:
    print "Please select a shape:"
    print "1  Rectangle"
    print "2  Circle"

    # Get the user's choice:
    shape = input("> ")

    # Calculate the area:
    if shape == 1:
        height = input("Please enter the height: ")
        width = input("Please enter the width: ")
        area = height*width
        print "The area is", area
    else:
        radius = input("Please enter the radius: ")
        area = 3.14*(radius**2)
        print "The area is", area

New things in this example:

  1. print used all by iself prints out an empty line
  2. == checks whether two things are equal, as opposed to =, which assigns the value on the right side to the variable on the left. This is an important distinction!
  3. ** is Python's power operator – thus the squared radius is written radius**2.
  4. print can print out more than one thing. Just separate them with commas. (They will be separated by single spaces in the output.)

The program is quite simple: It asks for a number, which tells it whether the user wants to calculate the area of a rectangle or a circle. Then, it uses an if-statement (conditional execution) to decide which block it should use for the area calculation. These two blocks are essentially the same as those used in the previous area examples. Notice how the comments make the code more readable. It has been said that the first commandment of programming is: "Thou shalt comment!" Anyway – it's a nice habit to acquire.

Exercise:

Extend the program above to include area calculations on squares, where the user only has to enter the length of one side. There is one thing you need to know to do this: If you have more than two choices, you can write something like:

    if foo == 1:
        # Do something...
    elif foo == 2:
        # Do something else...
    elif foo == 3:
        # Do something completely different...
    else:
        # If all else fails...

Here elif is a mysterious code which means "else if" :). So; if foo is one, then do something; otherwise, if foo is two, then do something else, etc. You might want to add other options to the programs too – like triangles or arbitrary polygons. It's up to you.

Loops

Sequential execution and conditionals are only two of the three fundamental building blocks of programming. The third is the loop. In the previous section I proposed a solution for checking if the spam was heated, but it was quite clearly inadequate. What if the spam wasn't finished the next time we checked either? How could we know how many times we needed to check it? The truth is, we couldn't. And we shouldn't have to. We should be able to ask the computer to keep checking until it was done. How do we do that? You guessed it – we use a loop, or repeated execution.

Python has two loop types: while-loops and for-loops. For-loops are perhaps the simplest. For instance:

    for food in "spam", "eggs", "tomatoes":
        print "I love", food

This means: For every element in the list "spam", "eggs", "tomatoes", print that you love it. The block inside the loop is executed once for every element, and each time, the current element is assigned to the variable food (in this case). Another example:

    for number in range(1,100):
        print "Hello, world!"
        print "Just", 100 - number, "more to go..."

    print "Hello, world"
    print "That was the last one... Phew!"

The function range returns a list of numbers in the range given (including the first, excluding the last... In this case, [1..99]). So, to paraphrase this:

The contents of the loop is executed for each number in the range of numbers from (and including) 1 up to (and excluding) 100. (What the loop body and the following statements actually do is left as an exercise.)

But this doesn't really help us with our cooking problem. If we want to check the spam a hundred times, then it would be quite a nice solution; but we don't know if that's enough – or if it's too much. We just want to keep checking it while it is not hot enough (or, until it is hot enough – a matter of point-of-view). So, we use while:

    # Spam-cooking program

    # Fetch the function sleep
    from time import sleep

    print "Please start cooking the spam. (I'll be back in 3 minutes.)"

    # Wait for 3 minutes (that is, 3*60 seconds)...
    sleep(180)

    print "I'm baaack :)"

    # How hot is hot enough?
    hot_enough = 50

    temperature = input("How hot is the spam? ")
    while temperature < hot_enough:
        print "Not hot enough... Cook it a bit more..."
        sleep(30)
        temperature = input("OK. How hot is it now? ")

    print "It's hot enough - You're done!"

New things in this example...

  1. Some useful functions are stored in modules and can be imported. In this case we import the function sleep (which sleeps for a given number of seconds) from the module time which comes with Python. (It is possible to make your own modules too...)

Exercise 1

Write a program that continually reads in numbers from the user and adds them together until the sum reaches 100. Write another program that reads 100 numbers from the user and prints out the sum.

Bigger Programs – Abstraction

If you want an overview of the contents of a book, you don't plow through all pages – you take a look at the table of contents, right? It simply lists the main topics of the book. Now – imagine writing a cookbook. Many of the recipes, like "Creamy Spam and Macaroni" and "Spam Swiss Pie" may contain similar things, like spam, in this case - yet you wouldn't want to repeat how to make spam in every recipe. (OK... So you don't actually make spam... But bear with me for the sake of example :)). You'd put the recipe for spam in a separate chapter, and simply refer to it in the other recipes. So – instead of writing the entire recipe every time, you only had to use the name of a chapter. In computer programming this is called abstraction.

Have we run into something like this already? Yup. Instead of telling the computer exactly how to get an answer from the user (OK - so we couldn't really do this... But we couldn't really make spam either, so there... :)) we simply used input - a function. We can actually make our own functions, to use for this kind of abstraction.

Let's say we want to find the largest integer that is less than a given positive number. For instance, given the number 2.7, this would be 2. This is often called the "floor" of the given number. (This could actually be done with built-in Python function int, but again, bear with me...) How would we do this? A simple solution would be to try all possibilities from zero:

    number = input("What is the number? ")

    floor = 0
    while floor <= number:
        floor = floor+1
    floor = floor-1

    print "The floor of", number, "is", floor

Notice that the loop ends when floor is no longer less than (or equal to) the number; we add one too much to it. Therefore we have to subtract one afterwards. What if we want to use this "floor"-thing in a complex mathematical expression? We would have to write the entire loop for every number that needed "floor"-ing. Not very nice... You have probably guessed what we will do instead: Put it all in a function of our own, called "floor":

    def floor(number):
        result = 0
        while result <= number:
            result = result+1
        result = result-1
        return result

New things in this example...

  1. Functions are defined with the keyword def, followed by their name and the expected parameters in parentheses.
  2. If the function is to return a value, this is done with the keyword return (which also automatically ends the function.

Now that we have defined it, we can use it like this:

    x = 2.7
    y = floor(2.7)

After this, y should have the value 2. It is also possible to make functions with more than one parameter:

    def sum(x,y):
        return x+y

Exercise 2

Write a function that implements Euclid's method for finding a common factor of two numbers. It works like this:

  1. You have two numbers, a and b, where a is larger than b
  2. You repeat the following until b becomes zero:
    1. a is changed to the value of b
    2. b is changed to the remainder when a (before the change) is divided by b (before the change)
  3. You then return the last value of a

Hints:

  • Use a and b as parameters to the function
  • Simply assume that a is greater than b
  • The remainder when x is divided by z is calculated by the expression x % z
  • Two variables can be assigned to simultaneously like this: x, y = y, y+1. Here x is given the value of y (that is, the value y had before the assignment) and y is incremented by one

More About Functions

How did the exercise go? Was it difficult? Still a bit confused about functions? Don't worry – I haven't left the topic quite yet.

The sort of abstraction we have used when building functions is often called procedural abstraction, and many languages use the word procedure along with the word function. Actually, the two concepts are different, but both are called functions in Python (since they are defined and used in the same way, more or less.)

What is the difference (in other languages) between functions and procedures? Well – as you saw in the previous section, functions can return a value. The difference lies in that procedures do not return such a value. In many ways, this way of dividing functions into two types – those who do and those who don't return values – can be quite useful.

A function that doesn't return a value (a "procedure") is used as a "sub-program" or subroutine. We call the function, and the program does some stuff, like making whipped cream or whatever. We can use this function in many places without rewriting the code. (This is called code reuse – more on that later.)

The usefulness of such a function (or procedure) lies in its side effects – it changes its environment (by mixing the suger and cream and whipping it, for instance...) Let's look at an example:

    def hello(who):
        print "Hello,", who

    hello("world")
    # Prints out "Hello, world"

Printing out stuff is considered a side effect, and since that is all this function does, it is quite typical for a so-called procedure. But... It doesn't really change its environment does it? How could it do that? Let's try:

    # The *wrong* way of doing it
    age = 0

    def setAge(a):
        age = a

    setAge(100)
    print age
    # Prints "0"

What's wrong here? The problem is that the function setAge creates it own local variable, also named age which is only seen inside setAge. How can we avoid that? We can use something called global variables.

Note: Global variables are not used much in Python. They easily lead to bad structure, or what is called spaghetti code. I use them here to lead up to more complex techniques - please avoid them if you can.

By telling the interpreter that a variable is global (done with a statement like global age) we effectively tell it to use the variable outside the function instead of creating a new local one. (So, it is global as opposed to local.) The program can then be rewritten like this:

    # The correct, but not-so-good way of doing it
    age = 0

    def setAge(a):
        global age
        age = a

    setAge(100)
    print age
    # Prints "100"

When you learn about objects (below), you'll see that a more appropriate way of doing this would be to use an object with an age property and a setAge method. In the section on data structures, you will also see some better examples of functions that change their environment.

Well – what about real functions, then? What is a function, really? Mathematical functions are like a kind of "machine" that gets some input and calculates a result. It will return the same result every time, when presented with the same input. For instance:

    def square(x):
        return x*x

This is the same as the mathematical function f(x)=x2. It behaves like a nice function, in that it only relies on its input, and it does not change its environment in any way.

So – I have outlined two ways of making functions: One type is more like a procedure, and doesn't return a result; the other is more like a mathematical function and doesn't do anything but returning a result (almost). Of course, it is possible to do something in between the two extremes, although when a function changes things, it should be clear that it does. You could signal this through its name, for instance by using only a noun for "pure" functions like square and an imperative for procedure-like functions like setAge.

More Ingredients – data structures

Well – you know a lot already: How to get input and give output, how to structure complicated algorithms (programs) and to perform arithmetic; and yet the best is still to come.

What ingredients have we been using in our programs up until now? Numbers and strings. Right? Kinda boring... No let's introduce a couple of other ingredients to make things a bit more exciting.

Data structures are ingredients that structure data. (Surprise, surprise...) A single number doesn't really have much structure, does it? But let's say we want more numbers put together to a single ingredient – that would have some structure. For instance, we might want a list of numbers. That's easy:

    [3,6,78,93]

I mentioned lists in the section on loops, but didn't really say much about them. Well – this is how you make them. Just list the elements, separated by commas and enclosed in brackets.

Let us jump into an example that calculates primes (numbers divisible only by themselves or 1):

    # Calculate all the primes below 1000
    # (Not the best way to do it, but...)

    result = [1]
    candidates = range(3,1000)
    base = 2
    product = base

    while candidates:
        while product < 1000:
            if product in candidates:
                candidates.remove(product)
            product = product+base
        result.append(base)
        base = candidates[0]
        product = base
        del candidates[0]

    result.append(base)
    print result

New things in this example...

  1. The built-in function range actually returns a list that can be used like all other lists. (It includes the first index, but not the last.)
  2. A list can be used as a logic variable. If it is not empty, then it is true – if it is empty, then it is false. Thus, while candidates means "while the list named candidates is not empty" or simply "while there are still candidates".
  3. You can write if someElement in someList to check if an element is in a list.
  4. You can write someList.remove(someElement) to remove someElement from someList.
  5. You can append an element to a list by using someList.append(something). Actually, you can use + too (as in someList = someList+[something]) but it is not as efficient.
  6. You can get at an element of a list by giving its position as a number (where the first element, strangely, is element 0) in brackets after the name of the list. Thus someList[3] is the fourth element of the list someList. (More on this below.)
  7. You can delete variables by using the keyword del. It can also be used (as here) to delete elements from a list. Thus del someList[0] deletes the first element of someList. If the list was [1,2,3] before the deletion, it would be [2,3] afterwards.

Before going on to explaining the mysteries of indexing list elements, I will give a brief explanation of the example.

This is a version of the ancient algorithm called "The Sieve of Erastothenes" (or something close to that). It considers a set (or in this case, a list) of candidate numbers, and then systematically removes the numbers known not to be primes. How do we know? Because they are products of two other numbers.

We start with a list of candidates containing numbers [2..999] – we know that 1 is a prime (actually, it may or may not be, depending on who you ask), and we wanted all primes below 1000. (Actually, our list of candidates is [3..999], but 2 is also a candidate, since it is our first base). We also have a list called result which at all times contains the updated results so far. To begin with, this list contains only the number 1. We also have a variable called base. For each iteration ("round") of the algorithm, we remove all numbers that are some multible of this base number (which is always the smallest of the candidates). After each iteration, we know that the smallest number left is a prime (since all the numbers that were products of the smaller ones are removed – get it?). Therefore, we add it to the result, set the new base to this number, and remove it from the candidate list (so we won't process it again.) When the candidate list is empty, the result list will contain all the primes. Clever, huh?

Things to think about: What is special with the first iteration? Here the base is 2, yet that too is removed in the "sieving"? Why? Why doesn't that happen to the other bases? Can we be sure that product is always in the candidate list when we want to remove it? Why?

Now – what next? Ah, yes... Indexing. And slicing. These are the ways to get at the individual elements of Python lists. You have already seen ordinary indexing in action. It is pretty straightforward. Actually, I have told you all you need to know about it, except for one thing: Negative indices count from the end of the list. So, someList[-1] is the last element of someList, someList[-2] is the element before that, and so on.

Slicing, however, should be new to you. It is similar to indexing, except with slicing you can target an entire slice of the list, and not just a single element. How is it done? Like this:

    food = ["spam","spam","eggs","sausages","spam"]

    print food[2:4]
    # Prints "['eggs', 'sausages']"

More Abstraction – Objects and Object-Oriented Programming

Now there's a buzz-word if ever there was one: "Object-oriented programming."

As the section title suggests, object-oriented programming is just another way of abstracting away details. Procedures abstract simple statements into more complex operations by giving them a name. In OOP, we don't just treat the operations this way, but objects. (Now, that must have been a big surprise, huh?) For instance, if we were to make a spam-cooking-program, instead of writing lots of procedures that dealt with the temperature, the time, the ingredients etc., we could lump it toghether into a spam-object. Or, perhaps we could have an oven-object and a clock-object too... Now, things like temperature would just be attributes of the spam-object, while the time could be read from the clock-object. And to make our program do something, we could teach our object some methods; for instance, the oven might know how to cook the spam etc.

So – how do we do this in Python? Well we can't just make an object directly. Instead of just making an oven, we make a recipe describing how ovens are. This recipe then describes a class of objects that we call ovens. A very simple oven class might be:

    class Oven:
        def insertSpam(self, spam):
            self.spam = spam

        def getSpam(self):
            return self.spam

Now, does this look weird, or what?

New things in this example...

  1. Classes of objects are defined with the keyword class.
  2. Class names usually start with capital letters, whereas functions and variables (as well as methods and attributes) start with lowercase letters.
  3. Methods (i.e. the functions or operations that the objects know how to do) are defined in the normal way, but inside the class block.
  4. All object methods should have a first parameter called self (or something similar...) The reason will (hopefully) become clear in a moment.
  5. Attributes and methods of an object are accessed like this: mySpam.temperature = 2, or dilbert.be_nice().

I would guess that some things are still a bit unclear about the example. For instance, what is this self thing? And, now that we have an object recipe (i.e. class), how do we actually make an object?

Let's tackle the last point first. An object is created by calling the classname as if it were a function:

    myOven = Oven()

myOven now contains an Oven object, usually called an instance of the class Oven. Let's assume that we have made a class Spam as well; then we could do something like:

    mySpam = Spam()
    myOven.insertSpam(mySpam)

myOven.spam would now contain mySpam. How come? Because, when we call one of the methods of an object, the first parameter, usually called self, always contains the object itself. (Clever, huh?) Thus, the line self.spam = spam sets the attribute spam of the current Oven object to the value of the parameter spam. Note that these are two different things, even though they are both called spam in this example.

Answer to Exercise 2

Here is a very concise version of the algorithm:

    def euclid(a,b):
        while b:
            a,b = b,a % b
        return a

References

[1]  Recipe for Fiesta Spam Salad taken from the Hormel Foods Digital Recipe Book

 


Copyright © Magnus Lie Hetland

如何系统学习python 系统学习Python编程语言是一个循序渐进的过程,涉及基础知识的学习、实践项目的演练、编程习惯的培养以及相关工具的熟练运用。 阅读详情

相关推荐

MD01和MD01N比较

摘要:MD01(传统MRP)与MD01N(MRP Live)是SAP系统不同版本的物料需求计划事务码。核心差异包括:MD01N取消MRP列表、简化计划规则、合并MPS/MRP操作、采用BAdI技术等,体现S/4HANA平台简化、标准化和智能化的演进方向。MD01N通过优化参数配置、增强筛选功能、利用HANA实时计算能力,实现了更高效的物料计划流程,代表了新一代计划引擎的技术革新。

SAP_LES_COM的博客 891

【Python】 Python编程基础练习100题学习记录第六期(51~60)

Python基础编程100题练习记录,GitHub高星项目。

分享自己学习过程获得的一些知识 702

010Editor实战:5分钟破解Zip伪加密文件(附BUUCTF真题解析)

本文详细介绍了如何使用010Editor快速破解Zip伪加密文件,包括BUUCTF真题的完整解析。通过修改关键字节,轻松解除伪加密状态,适用于CTF竞赛和实际工作场景,提升文件处理效率。

weixin_29325007的博客 326

在学习Python时遇到的一些项目bug

Python项目运行遇到的错误

Januea的博客 7740

maxwell与steady state thermal 通过workbench耦合仿真

文章目录maxwellsteady state thermal maxwell 1加入maxwell并打开 2导入模型 3选择求解器类型:涡流求解器eddy current 4修改模型名字不能带_等特殊符号 5为模型赋材料 6设立3D边界,各边电流进出方向为0其余方向300 7设置激励条件,可设置电流大小,相位,方向 8设置集肤深度,选取中间铜导体的体然后设置,如何设置看帮助文档 9求解设置 迭代步数 收敛精度 交流电频率 10验证条件满足计算 11求解 发现无法求解,删除ai

roymustang的博客 9201

秋招突击——笔试整理——8/25——拼多多笔试整理

继续加油! 转变思维,有简单到复杂,由直观到抽象,这种贪心模拟的题目一直是这样的!

Blackoutdragon的博客 2400

理解 Python 类的变量,方法与属性

熟悉了传统的 C++/Java类定义的风格,来感受一下 Python是如何定义类的。本篇是阅读 《The Quick Python Book》第二版关于类定义的笔记,由原书内容进一步引申,不过是依照本人的思考顺序来组织的。在理解Python类定义的同时头脑中应该闪现出JavaScript/Java如何定义类的情景。 最简单的类定义 class MyClass: p...

Python学习Q群696455390 1016

MobaXterm简介和使用(服务器连接工具)

MobaXterm 是一个功能强大的远程计算工具,集成了许多常用的远程计算功能,包括 SSH、X11、RDP、VNC、FTP、SFTP 等。

清平乐的技术专栏 1946

pycharm提示:Usually first parameter of a method is named 'self'

定义在类中的函数的第一个参数通常为self 加个self就好了 参考文章:python 在python的class中的,self到底是什么?

Dontla的博客 3662

代码的自由之旅:用AI写出无版权烦恼的Verilog

他们还基于这个数据集,训练了一个名叫“FreeV”的AI模型,不仅能写出好用的Verilog代码,还把版权侵权的风险降到了仅3%。为了让AI安全地写Verilog,研究团队提出了三个“法宝”:一个检测AI是否会生成侵权代码的测试方法、一个干净的Verilog数据集FreeSet,还有一个基于FreeSet训练的AI模型FreeV。AI的记忆力超强,能记住训练时见过的代码。测试发现,一些用Verilog数据训练过的AI,比如VeriGen,生成侵权代码的概率从9%涨到了15%,说明它们可能学了不该学的代码。

步子哥的博客 1810

YOLOv8改进 | 卷积模块 | 用DWConv卷积替换Conv【轻量化网络】

YOLOv8改进,yolov8,yolov8创新,yolov8涨点

kay_545 7156

Python — 面向对象(1)

Python面向对象中的基础概念,介绍类定义、类对象、类实力,以及方法和函数的区别。

DgLink的博客 1629

L2CAP 面向连接信道(CoC)在 BLE 中的应用:建立、流控与数据传输

L2CAP(逻辑链路控制与适配协议)是蓝牙协议栈中的核心层,位于基带层之上,为上层协议提供数据传输服务。在低功耗蓝牙(BLE)中,L2CAP面向连接信道(Connection-Oriented Channel, CoC) 是实现可靠数据传输的关键机制,广泛应用于健康监测、智能家居、工业控制等领域。

byte轻骑兵的技术小窝 3634

想学习下Python和深度学习,Python需要学习到什么程度呢?

想要学习Python和深度学习,Python的学习程度需要达到能够熟练运用这门语言进行编程,并能够理解和实现深度学习模型的基本构建和训练过程。作者:[美] 阿尔·斯维加特(Al Sweigart)简介:本书是一本面向初学者的Python编程实用指南。本书不仅介绍了Python语言的基础知识,而且通过案例实践教读者如何使用这些知识和技能。本书的第一部分介绍了基本的Python编程概念,第二部分介绍了一些不同的任务,通过编写,可以让计算机自动完成它们。第二部分的每一章都有一些项目程序供读者学习。

人邮异步社区 1575

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Python机器学习学习线路

Python机器学习学习线路是一个循序渐进的过程,需要您不断积累知识和实践经验。通过掌握基础知识、学习机器学习基本方法和高级技术,以及参与实践项目,您将逐渐成为一名合格的机器学习工程师。希望本文能为您的Python机器学习学习之路提供有益的指导。

努力让自己发光,对的人才能迎着光而来 10万+

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Python学习记录

Python学习记录

肥猫 1万+

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

python学习_Python学习资料

1、Python学习以及人工智能方向: https://pan.baidu.com/s/1kUYJ1weVhK-2vW1CXAZgQA 密码:haxq2、Python3入门与进阶:https://pan.baidu.com/s/1q-WLk0Ggb3lSXTmPBs6C_w 密码:sov73、python神经网络算法与深度学习视频教程人工智能:https://pan.baidu.com/s/115...

weixin_39782355的博客 877

python学习方法_学习Python的5种方法

python学习方法 Python是一种功能强大的通用编程语言,在开源软件开发人员中很流行。 无论您是想测试代码的经验丰富的开发人员,还是只想学习基础知识的人,以下资源都可能会有所帮助。 1. Codecademy:动手方法 您喜欢动手学习的方法吗? 尝试Codecademy 。 Codecademy课程包括课程,项目和测验,以帮助您学习Python和其他编码语言。 免费帐户授予访问交互...

cumo3681的博客 1582

Python学习分享 学习Python的10个技巧

Python是最广泛和最通用的编程语言之一。它也是最受欢迎的初学者之一,在世界各地的学校中可以说是最广泛教授的语言。如果你对编程或编码感兴趣,你可能会考虑尝试学习Python,我会说这是一个好主意! 但是,学习Python并不是一件有趣的游戏。首先,找到在线学习Python的最佳方法本身很难。有数以千计的不同课程和教程,都声称是最好的。考虑到这一点,我已经列出了我学习Python的十大技巧列表。...

weixin_41754736的博客 515

怎样学习Python

之前接触的很多同学都会说,学习后面的内容,前面的知识点就忘记了。这种现象非常符合遗忘曲线,之所以会忘记,主要是因为没有反复的加强记忆或者没有深刻理解知识点的应用场景。尤其在Python初级阶段学习过程中,有非常多概念性的内容,如果不及时总结加强记忆,必然会出现学习后面的内容,前面的知识点已经忘记了。那应该如何总结呢?作为程序员经常使用的笔记工具是Markdown和JupyterNotebook,这两个工具在配置完成后,能够非常好的记录文本以及代码内容。

m0_59236602的博客 362

关于学习python的建议

一、前提部分 有计算机的常识。至少在安装Python,调环境变量能够看着教程能跟上,常识性的东西就随便翻翻书就行了。 二、基础部分 可以跟着廖雪峰的教程学,很好的教程 可以跟着骆昊的Python100天 可以查阅菜鸟教程当一本字典 三、书籍推荐 Learn Python the Hard Way Think Python: How to Think Like a Computer Scient...

发现问题,并解决问题,批判性思维 1234

基于 Python 的机器学习总结

机器学习项目通常遵循一定的流程,以 Python 为工具,我们可以高效地完成每一个环节。数据收集:从各种数据源,如数据库、文件系统、网络爬虫等获取原始数据。Python 提供了丰富的库来实现数据的读取,如pandas可以轻松读取 CSV、Excel、SQL 等多种格式的数据,requests库可以用于从网页爬取数据。数据预处理:原始数据往往存在缺失值、异常值、噪声等问题,需要进行预处理。使用pandas可以方便地处理缺失值(如删除缺失行或填充缺失值)、清洗数据;Numpy可以对数据进行数值计算和变换;

2401_83196531的博客 1853

学习python多久?该如何学习python?

学习python是大家进入编程世界的理想之选,因为它简单、易学、容易入门,当然在学习python之前很多人会关注python学习的周期等问题,接下来一起来看看吧。 学习python需要多久? 目前市面上python开发技术培训的时间一般4-6个月之间,根据选择的方向不同,需要学习的时间也是不同的。对于零基础的学员来说更不同,简单的来讲,即便是零基础学习python开发技术也是如此,自身条件很重要。 如何学习python技术? 时间安排:无论是对于python技术人员还是学习其他技术,编程人员对于时间的安排必

weixin_48219119的博客 644

怎样学习python语言_如何学习python语言

如何学习python语言?书声琅琅教育番茄老师微信pykf20介绍,目前中国互联网发展迅速,并且人工智能得到了飞速的发展,社会对自动化运维要求越来越高,而python语言在这块有得天独厚的优势,越来越多的朋友想学习python,而不知道如何来学习,那么今天我们来聊一聊如何学习python语言的话题。python语言很神秘吗Python作为一款类自然语言的编程语言,很方便的就可以上手,而且可以说是老...

weixin_39878855的博客 273

python 机器学习_如何使用 Python学习机器学习

随着数据科学(Data Science)技术的兴起,人工智能(ArtificialIntelligence)、机器学习(Machine Learning)成为近几年来计算机科学界十分热门的研究领域,如今在实体和在线的学习机器学习的资源有很多,本文整理了一些好用学习资源希望帮助初学者能更容易使用 Python 入门机器学习的领域中,从零开始学习机器学习。若是对于数据科学不熟悉的读者可以先...

weixin_39816448的博客 342

《Python学习手册》学习总结

《Python学习手册》学习总结下载地址: [ Python学习手册第4版 ](https://www.jb51.net/books/60827.html)第三章 如何运行程序第四章 介绍Python对象类型第五章 数字第六章 动态类型简介第七章 字符串第八章 列表第9章 元组、文件及其他第10章 Python语句简介第11章 赋值、表达式和打印第12章 if测试第13章 while和for循环第十四章 文档第十五章 函数基础第十六章 作用域与参数第17章 函数的高级话题第18章 模块:宏伟蓝图第19章 模

thelao的博客 491
上一篇: [学习笔记]Thinking in Java (the 2nd edition) Study Note (4)
下一篇: [学习小记]Java的反射机制
Gooing
博客等级 码龄24年 4粉丝 59原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值