{"slug": "godzilla-dev-ai-x-quant-trader-series-day-2", "title": "godzilla.dev — AI x Quant Trader Series — Day 2", "summary": "A developer at godzilla.dev continues an AI x Quant Trader series with a Python tutorial covering functions, loops, conditionals, and classes. The tutorial explains defining functions with variable parameters, if/elif/else statements, while loops with break, for loops, and list comprehensions. It also introduces object-oriented programming concepts such as classes and objects.", "body_md": "source: [https://godzilla.dev/learning/ai_quant_traders_series_2/](https://godzilla.dev/learning/ai_quant_traders_series_2/)\n\nSee below for godzilla.dev materials about: AI x Quant Trader Series - Day 2\n\n\"Who will teach me about Python?\"¶\n\nOn the first day, We learned the basic operations of Python and several main container types.\n\nToday, We will learn Python's functions, loops and conditionals, and classes. With this, We will have a general understanding of Python. The learning outline for today is as follows:\n\nFunctions¶\n\na) Defining a function\n\nLoops and Conditionals¶\n\na) if statements\n\nb) while True / break statements\n\nc) for loops\n\nd) List comprehensions\n\nb) Defining a class\n\nWhen introducing list methods, we already briefly mentioned functions. Anyone who has studied mathematics knows what a function is — it takes an input (a parameter) and returns a value. Functions can also be defined by yourself, using the following format:\n\ndef function_name(parameter):\n\n# function code\n\nIn the function code, return indicates the value to be returned. For example, to define a square function square(x) that takes x as input and returns the square of x:\n\ndef square(x):return x*x\n\nsquare(9)\n\nthe output:\n\n81\n\n(2) Defining Functions with Variable Parameters\n\nSometimes you need to define a function with a variable number of parameters. There are several ways to do this:\n\nAssign default values to parameters For example, define a function like f(a, b=1, c='hehe'). In this case, the last two parameters are optional — if not specified during the function call, they will default to b=1 and c='hehe'. Therefore, the following calls are all valid:\n\nf('dsds')\n\nf('dsds', 2)\n\nf('dsds', 2, 'hdasda')\n\nKeyword arguments The method above fixes the order of parameters — the first value is assigned to the first parameter. With keyword arguments, however, you can specify which value goes to which parameter by name. For example, still using the function f(a, b=1, c='hehe'), you can call it like this:\n\nf(b=2, a=11)\n\nThe order of parameters can be changed as long as you specify them using their keywords.\n\na) if statements¶\n\nAlso note two things: first, indentation; and second, a colon (:) is required after the condition.\n\nj=2.67\n\nif j<3:\n\nprint('j<3')\n\nthe output:\n\nj<3\n\nFor multiple conditions, note that elseif should be written as elif. The standard format is:\n\nif condition1:\n\nstatement1\n\nelif condition2:\n\nstatement2\n\nelse:\n\nstatement3\n\nNote that if, elif, and else are at the same indentation level — there should be no indentation before them.\n\nt=3\n\nif t<3:\n\nprint('t<3')\n\nelif t==3:\n\nprint('t=3')\n\nelse:\n\nprint('t>3')\n\nthe output:\n\nt=3\n\nb) while True / break statements¶\n\nThe format of this statement is:\n\nwhile True: # condition is true\n\nstatement\n\nif break_condition:\n\nbreak\n\nHere’s an example:\n\na=3\n\nwhile a<10:\n\na=a+1\n\nprint(a)\n\nif a==8: break\n\nthe output:\n\n4\n\n5\n\n6\n\n7\n\n8\n\nAlthough the condition after while is a < 10, meaning the loop will continue as long as a is less than 10, the if condition specifies that the loop should break when a equals 8. Therefore, the output will only go up to 8.\n\nc) for loops¶\n\nNo more explanation needed — you can iterate over a sequence, dictionary, etc.\n\na=[1,2,3,4,5]\n\nfor i in a:\n\nprint(i)\n\nthe output:\n\n1\n\n2\n\n3\n\n4\n\n5\n\nd) List comprehensions¶\n\nList comprehensions are a way to create a new list from an existing one, working similarly to a for loop. The format is:\n\n[output_value for condition]\n\nWhen the condition is met, an output value is generated, and the final result is a list.\n\n[x*x for x in range(10)]\n\nthe output:\n\n[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n\n[x*x for x in range(10) if x%3==0]\n\nthe output:\n\n[0, 9, 36, 81]\n\nThe above example uses the sequence [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] to generate a new sequence.\n\nAn object, on the other hand, is a concrete instance of a class. It is something that actually exists. If \"Person\" is an abstract class, then you, yourself, are a specific object of that class.\n\nAn object of a class is also called an instance of the class. To give another analogy, a class is like a mold, and objects are the concrete things produced using that mold — each with the same attributes and methods. As the saying goes, \"They look just alike, as if made from the same mold\" — that’s exactly the idea here.\n\nThe process of using a mold to create a concrete thing is called instantiation of the class. Let’s take a look at a specific class example below:\n\nb) Defining a class¶\n\nclass boy:\n\ngender='male'\n\ninterest='girl'\n\ndef say(self):\n\nreturn 'i am a boy'\n\nThe statement above defines a class called boy. Now let’s use this class model to construct a specific object:\n\npeter=boy()\n\nNow let’s take a look at the attributes and methods of the specific instance peter.\n\n“What are attributes and methods?”\n\nThey are two forms of a class:\n\nAttributes are the static aspects\n\nMethods are the dynamic aspects\n\nFor example, the class “Person” may have attributes such as name, gender, height, age, and weight. It may also have methods such as walking, running, and jumping.\n\npeter.gender\n\nthe output:\n\n'male'\n\npeter.interest\n\nthe output:\n\n'girl'\n\npeter.say()\n\nthe output:\n\n'i am a boy'\n\nHere, gender and interest are attributes of peter, while say is his method. If we instantiate another object, for example sam:\n\nsam=boy()\n\nThen sam and peter have the same attributes and methods — you could say, “They were truly made from the same mold!”\n\nLearning more fromhttps://godzilla.dev/", "url": "https://wpnews.pro/news/godzilla-dev-ai-x-quant-trader-series-day-2", "canonical_source": "https://dev.to/kx_31eaa481780171271d692f/godzilladev-ai-x-quant-trader-series-day-2-57m4", "published_at": "2026-07-04 04:04:53+00:00", "updated_at": "2026-07-04 04:18:53.369041+00:00", "lang": "en", "topics": ["developer-tools", "machine-learning"], "entities": ["godzilla.dev", "Python"], "alternates": {"html": "https://wpnews.pro/news/godzilla-dev-ai-x-quant-trader-series-day-2", "markdown": "https://wpnews.pro/news/godzilla-dev-ai-x-quant-trader-series-day-2.md", "text": "https://wpnews.pro/news/godzilla-dev-ai-x-quant-trader-series-day-2.txt", "jsonld": "https://wpnews.pro/news/godzilla-dev-ai-x-quant-trader-series-day-2.jsonld"}}