茱莉亚分形_茱莉亚的条件和方法介绍

茱莉亚分形

Julia综合教程(The Comprehensive Julia Tutorial)

Video for this article

本文视频

介绍(Introduction)

In the last edition of The Comprehensive Julia Tutorial, we took a look at installing Julia, Julia’s package manager (Pkg,) and we also took a short look at types inside of the Julia language. If you have not seen that tutorial, you can check it out here:

在《 Julia综合指南》的上一版中,我们研究了安装Julia的软件包管理器(Pkg)Julia的过程,并简要介绍了Julia语言内部的类型。 如果您还没有看过该教程,可以在这里查看:

Today we are going to take a look at actually writing functions to deal with our types, as well as a broad overview of how conditionals work inside the Julia language. On top of that, we will go a bit further into the world of types and look at a few more types that we have at our disposal. Here is a link to today’s notebook and Github repo, as well:

今天,我们将看看实际编写函数来处理我们的类型,以及对条件在Julia语言中的工作原理的广泛概述。 最重要的是,我们将进一步探讨类型的世界,并研究我们可以使用的其他一些类型。 这也是今天的笔记本和Github存储库的链接:

功能 (Functions)

In Julia, most functions are also going to be methods. This is because essentially every function we call is likely going to need to be provided parameters. This is of course a quality of the functional programming paradigm that Julia holds, but there are ways to get around this which we will get into so take this statement with a grain of salt. In Julia, we can create a function by using the “ function” key-word.

在Julia中,大多数功能也将成为方法。 这是因为从本质上讲,我们调用的每个函数都可能需要提供参数。 当然,这是Julia所拥有的函数式编程范式的一种品质,但是我们有很多方法可以解决这个问题,因此请一言以蔽之。 在Julia中,我们可以使用“功能”关键字创建一个功能。

function foo(parameter)
code_here
end

We will also end it by using the “ end” key-word. Functions take parameters, which are arguments that will be provided when we go to use the function in the future. They will also be the variables that we will potentially be working with inside of our code.

我们还将使用“ end”关键字结束它。 函数带有参数,这是将来我们要使用该函数时将提供的参数。 它们也将是我们可能在代码内部使用的变量。

有条件的 (Conditionals)

As with most other languages, a conditional in Julia needs an operator that will return a boolean type, rather than a number, or assignment. The boolean operator for “ is equal” is ==, for example. If we were to use this operator with 5 and 5, we wouldn’t be setting 5 equal to 5, but instead we would be returning whether or not the two are equal.

与大多数其他语言一样,Julia中的条件语句需要一个运算符,该运算符将返回布尔类型,而不是数字或赋值。 例如,“等于”的布尔运算符为==。 如果我们将此运算符与5和5一起使用,则不会将5设置为等于5,而是将返回两者是否相等。

5 == 5true

There are three different types of conditions that you can run in Julia:

您可以在Julia中运行三种不同类型的条件:

  • If — If this is true, then execute the following code.

    如果-如果为true,则执行以下代码。
  • Elseif — If any condition before is not met, and this is true, then execute the following code.

    Elseif —如果不满足之前的任何条件,并且为真,则执行以下代码。
  • Else — If none of the conditions in this statement are true, then execute the following code.

    否则-如果此语句中的所有条件都不成立,则执行以下代码。

Of course, you don’t want to use statements like elseif when another if is what is required, because the code ran inside of that check will be ignored if a prior condition is met.

当然,当需要另一个if时,您不想使用elseif之类的语句,因为如果满足先决条件,则在该检查内运行的代码将被忽略。

有关类型的更多信息 (More On Types)

Types are a pretty enormous staple in the Julia language: they are incredibly important to how the language works. Methods themselves are considered types, as well as all of the default data-types that we have looked at so far. A lot of data-types in Julia have their own delimiters or expressions that identify their types. An example of this would be strings, which use quotation marks to mark their beginning and end.

类型是Julia语言中非常重要的组成部分:它们对于语言的工作方式极为重要。 方法本身被视为类型,以及到目前为止我们所研究的所有默认数据类型。 Julia中的许多数据类型都有自己的定界符或表示它们类型的表达式。 一个示例就是字符串,该字符串使用引号标记其开始和结束。

Another example of this is in chars, which use an apostrophe to mark their beginning and their end. Furthermore, symbols and arrays also have their own identifiers that make it relatively straightforward for the language to analyze what type we are trying to create in each scenario.

字符的另一个示例是char,它们使用撇号标记其开始和结束。 此外,符号和数组还具有自己的标识符,这使得该语言可以相对简单地分析我们在每种情况下试图创建的类型。

String => "Hello"
Char => 'h'
Symbol => :Symb
Array => [5, 10, 15]

结论 (Conclusion)

Although it might seem like we are in the basic throws of the Julia language right now, I am confident that those keeping up with these tutorials will be Julian masters in no time! Julia is a great language for both scientific and software-engineering applications, and I think it will be a great addition to your arsenal! On top of that, it is rather beginner friendly and easy to learn, so I think even with relatively speedy teaching, it will be simple to pick up on. That being said, I do appreciate feedback on whether there is too much speed, too many details, or if I am going too slow! Thank you for reading!

尽管现在看来我们已经掌握了Julia语言,但我相信跟上这些教程的人将很快成为Julian的专家! Julia对于科学和软件工程应用程序来说都是一门伟大的语言,我认为它将对您的武器库大有助益! 最重要的是,它对初学者非常友好且易于学习,因此我认为即使教学相对较快,也很容易上手。 话虽这么说,我非常感谢反馈有关速度是否太快,细节太多或我走得太慢! 感谢您的阅读!

翻译自: https://towardsdatascience.com/an-introduction-to-conditions-and-methods-in-julia-a94de842b9f9

茱莉亚分形

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值