Oh, wow, thank you so much for that question!
I only started playing a few months ago, and am currently playing in one weekly campaign and running an infrequent campaign myself. So, uh. I think there’s one thing I can say for sure:
Abandon your expectations.
No, really. Just go into the game not expecting anything, that leaves you more open to what’s going to happen. Of course, only to a certain degree. Like, I know when you do this with friends, maybe your options aren’t all that open, but it helps to ask the DM what kind of game they’re running – if it’s more RP-heavy or more of a hack and slash affair. But this is about the only thing you should be expecting. Well, also decency at the table, and maybe for everyone to be clear of the degree of gory details when it comes to the fighting stuff. You know, the groundworks.
Other than that? Keep an open mind! That goes for both playing and running a game. Try and work with the other players and the DM, and never against any of them – not even the DM, even if they’re also playing your enemies. It’s supposed to be cooperative storytelling and a good time for all. If your DM is worth the title, they won’t purposefully try to screw you over or just kill off as many characters as possible.
Or maybe you all have previously agreed that that’s your thing! Some people like playing that way, too, and more power to them!
My favorite style to play is different though, and largely based on improv and just trying to make everyone else look good, so they’ll do the same in return. And the best way to go about doing improv is to just not have any expectations and be completely open for whatever is thrown at you. It’s the “yes, and” thing they quote on critical role on occasion (which I’m pretty sure is the reason anyone would ask me about D&Db :D). You accept what everyone else gives you and work with that and the only thing you expect is the same courtesy in return.
Oh, also, know your character, your abilities, and your spells. There is nothing more annyoing to a DM than having to look up how your character works. Usually they will know, but, you know, being a DM means you have a lot of wheels spinning, so the less they have to look up for you, the better.