Data Types (part 1) - Value Types | Vyper (0.2) - Phụ đề song ngữ

Let's learn about the different data types in Piper.
Each data type is either a value or a reference.
In this video, we'll go over value types, and in the next video, we'll go over references.
First of all, what are value types?
value types are data types that are passed by their values.
For example, let's say that we have an unsigned integer named x and it is equal to 1.
And then we reassign variable x to a variable named y.
And then we modify the variable y.
For example, we add one to its current value.
Now the big question is, what is the value of x?
And the answer is x is still equal to one.
This is because when we assign x to y, the value of x was copied over to a variable y.
So that when we change the value of variable y, it doesn't change the value of x.
So that's value types.
They copy variables by their variable y.
so that making a change to one variable does not affect the other variable.
Let's now take a look at value types available in Viper.
The first value type that I'm going to show you is a Boolean.
So I'll name it B and then we'll say it's a public variable and up type.
Boo.
By declaring this variable as public, we'll be able to access this variable after we deploy it using Remix.
I'll make a separate video about the different visibility of the variable.
For now let's just go over what this line of code is doing.
Here we're declaring our variable named called b.
The type of this variable is a boolean and it is a public variable which means that we'll be able to get the value of this b variable after the contract is deployed.
All moving on another value type is int 128.
So we will name it i and then it will be public and we can declare the type has int 128.
The range of this variable goes from negative 2 to the 127 to 2 to the 127.
So this is the data type that you will want to use when you want to handle both negative and positive numbers.
Next, we have Uint 256, which ranges from 0 to 256 minus 1.
and this is the variable to use when you're only dealing with non-negative numbers.
In Viper we also have decimals.
The range of decimals is same as in 128 and it supports up to 10 decimal places.
Now this is a useful data type that is not available in Solidity.
Alright, moving on, we have our address type.
Bites 32 and it's useful when you want to store the cryptographic cache of something.
Now surprisingly we also have byte arrays and strings as value types.
So this means that every time you copy a byte array or a string, it will copy each element in the array.
If you have a string of length 1000 and then reassign it to another variable.
Basically are running a for loop for 1000 characters copying each element.
Let's quickly go over what these two lines of code are doing.
For the first one, BS, we're declaring a variable named BS, and it's a public variable.
The data type is bytes, and this byte is at most 100.
Likewise, first chains were declaring a variable named s, it's a public variable,
of type string, and this variable can be at most 100 characters long.
These are the value types available in Viper.
Let's set these variables to some concrete value.
So we'll define init function.
And the first thing that we need to do is say, add external, and say def to underscores init to underscores parentheses calling.
Now this external means that this init function can be called from outside of the contract.
and then we'll set the variable b to true by saying self dot b equals true.
We'll set i to minus 1 by saying self dot i equals minus 1.
We'll set the unsigned variable to some positive number.
We want to We'll set the decimal to 3.14 and we'll set the address type to some random
address and then the bytes 32 to also some random bytes 32.
The byte array,
we also set it to some random byte,
and we'll say that it's a byte by prefixing with a b, double quotes, slash x, and then the value, 0, 1.
For the string, we'll say this is a string.
Let's make sure that this contract compiles.
So I'm going to open my terminal and type Viper, followed by the name of the contract here.
I named it value types.
And you can see that our contract compile is run through a demo using remix.
So I'm going to copy the code.
Open remix.
And then activate Viper.
Next, I'll create a Viper file.
Here, I'll name it value type.by paste the code.
And then click on the biker compiler and then click remote compiler and then click compile All right,
let's deploy this contract,
so I'm gonna click deploy scroll down and then click on the contract that was just deployed and let's check that
these variables are set to these values over here address b is for boolean b32 is bytes 32 bs is bytes array g is decimal.
Note that remix does not know how to handle decimal types yet.
Alright, moving on, let's check the value of int 128.
It's equal to minus one.
the string value, this is a string, and the on-site value is 1 to 3, right?
So are the value types of Viper, Boolean, on-site and signed integers, decimals, edges, bytes 32, and also strings and bytes array.
The last two data types being a value type is a little bit surprising, since in Solidity these two types are reference types.

Mở khóa nhiều tính năng hơn

Cài đặt tiện ích Trancy để mở khóa nhiều tính năng hơn, bao gồm phụ đề AI, định nghĩa từ AI, phân tích ngữ pháp AI, nói chuyện AI, v.v.

feature cover

Tương thích với các nền tảng video chính

Trancy không chỉ cung cấp hỗ trợ phụ đề song ngữ cho các nền tảng như YouTube, Netflix, Udemy, Disney+, TED, edX, Kehan, Coursera, mà còn cung cấp dịch từ/câu bằng AI, dịch toàn văn sâu sắc và các tính năng khác cho các trang web thông thường. Đây là một trợ lý học ngôn ngữ đa năng thực sự.

Trình duyệt trên tất cả các nền tảng

Trancy hỗ trợ tất cả các trình duyệt trên tất cả các nền tảng, bao gồm tiện ích trình duyệt iOS Safari.

Nhiều chế độ xem

Hỗ trợ chế độ xem rạp, đọc, kết hợp và các chế độ xem khác để có trải nghiệm song ngữ toàn diện.

Nhiều chế độ luyện tập

Hỗ trợ luyện viết câu, đánh giá nói, trắc nghiệm nhiều lựa chọn, viết theo mẫu và các chế độ luyện tập khác.

Tóm tắt video AI

Sử dụng OpenAI để tóm tắt video và nắm bắt nhanh nội dung chính.

Phụ đề AI

Tạo phụ đề AI chính xác và nhanh chóng trên YouTube chỉ trong 3-5 phút.

Định nghĩa từ AI

Chạm vào từ trong phụ đề để tra cứu định nghĩa, với định nghĩa dựa trên AI.

Phân tích ngữ pháp AI

Phân tích ngữ pháp câu để nhanh chóng hiểu ý nghĩa câu và nắm vững các điểm ngữ pháp khó.

Nhiều tính năng web khác

Ngoài phụ đề song ngữ cho video, Trancy còn cung cấp dịch từ và dịch toàn văn cho các trang web.

Sẵn sàng để bắt đầu

Hãy thử Trancy ngay hôm nay và trải nghiệm các tính năng độc đáo của nó cho chính bạn

Tải về